My problem here is I want to have any keystroke the user types execute a automatic keystroke. However, I would like only the user generated keystroke to be suppressed. I am trying to do this with pynput like this:
def on_press(key):
if key == keyboard.Key.esc:
return False
def on_release(key):
if key == keyboard.Key.esc:
return False
elif len(words) > i:
c.press(words[i])
i += 1
else:
c.press(keyboard.Key.space)
return False
with keyboard.Listener(on_press=on_press, on_release=on_release, suppress=True) as listener:
listener.join()
I think that the problem is that the keypress call inside of the on_press() function also calls to the listener function and this creates infinite recursion. If I keep the suppressor on nothing is typed but the program keeps infinitely recursing. If I turn the suppressor off both the user keypress is executed and the autogenerated key press is executed recursively.
But if I keypress outside of the on_press() function like below it only executes if I exit the listener.
with keyboard.Listener(on_press=on_press, on_release=on_release, suppress=True) as listener:
listener.join()
if key == keyboard.Key.esc:
return False
elif len(words) > i:
c.press(words[i])
i += 1
else:
c.press(keyboard.Key.space)
return False
Does anyone have a workaround to this?