pynput
pynput copied to clipboard
pynput listens to automatic keystrokes
Hi, I have this issue:
Say I register a keyboard listener like this :
keyboard = pynput.keyboard.Controller()
def on_each_key_press(key):
print(key)
if(key==Key.enter):#make the pynput type a whenever Enter is pressed
keyboard.type("a")
if key == Key.esc:
# Stop listener
return False
def run():
with Listener(
on_press = on_each_key_press,
) as listener:
listener.join()`
This is the output: (I pressed the shift and # and ENTER keys myself)
Key.shift pressed
'#' pressed
Key.enter pressed
pynput types a
'a' pressed
Then the pynput will not only listen to the keys the user types, but it will also listen to the keys that pynput auto types (i.e the "a" after the ENTER key is pressed)
is there a way to stop pynput from tracking its own input?
@Abelcanc3rhack3r
If you're on Windows, you can use win32_event_filter like this
Alternatively, you can try my more high-level version, which does this automatically :)