Python3 - Globally capture key presses while stopping other programs receiving them
I want some Python3 that captures real key presses globally (regardless of focus on a window) but stops the focused window getting the real key presses. An end goal example: A user types "apple" while focused on a text editor window, the script is logging all key presses and detects the user has typed one of its trigger words "apple", so it then sends virtual keys typing "orange". The text editor now reads only "orange"; it never received the real key presses ("apple"), only those sent by the script ("orange"). I need it to not just delete the actually typed characters afterwards.
I have been using the "keyboard" module. I have it detecting real key presses and sending virtual key presses when it detects certain strings of real key presses, but currently everything receives the real and virtual key presses. I only want them receiving the virtual ones. (Using the terms from the example: The text editor reads "appleorange" not just "orange".)