keyboard: on_press and on_release not executing if one is placed after another
Hi, I’m using on_press and on_release to store any currently pressed keys. Unfortunately, if on_press is placed before on_release, on_release is not being executed. If I switch places of on_press with on_release, then on_press is not being executed.
Because of it, I’m using hook as a workaround, in which I’m checking event_type and calling proper function.
pressed_keys = []
def add_key(key):
pressed_keys.append(key)
return
def remove_key(key):
pressed_keys.remove(key)
return
keyboard.on_press(add_key)
keyboard.on_release(remove_key) #This is not being executed
Also I have one question: Is there a simpler way of checking in on_press_key if other keys are also currently pressed? modifiers is always empty.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 15 (3 by maintainers)
Hello,
I was trying to do the same exact thing with
on_pressandon_release. It looks like the bug was introduced in a recent update (pip version 0.13.1). I downgraded to version 0.11.0 and that got rid of the bug.To install version 0.11.0 I used the command:
pip install keyboard==0.11.0Hope this helps!