pynput
pynput copied to clipboard
Numpad KeyCode detection not working since updating to 1.7.1
Since updating to 1.7.1, my script no longer detects key combinations with numpad keys. :(
Seems to only affect keys that are detected using the vk KeyCode parameter.
Here is some sample code
import threading
from pynput import keyboard
import time
mode = "Debug"
#Debug Code
def debug(text):
if mode == "Debug":
print(text)
debug("---------------------")
#Keyboard Shortcut Combinations
COMBINATIONS = [
{keyboard.Key.alt_l, keyboard.KeyCode(vk=102)}, #NumPad 6
{keyboard.Key.alt_l, keyboard.KeyCode(char='6')}, #NumRow 6
]
# The currently active modifiers
current = set()
def execute():
if keyboard.KeyCode(vk=102) in current and keyboard.Key.alt_l in current:
debug("Pressed AltL + NumPad6") #Never gets triggered
if keyboard.KeyCode(char='6') in current and keyboard.Key.alt_l in current:
debug("Pressed AltL + NumRow6") #Gets triggered normally
def on_press(key):
if any([key in COMBO for COMBO in COMBINATIONS]):
current.add(key)
debug(current)
if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
execute()
def on_release(key):
if any([key in COMBO for COMBO in COMBINATIONS]):
try:
current.remove(key)
except KeyError:
pass
def keyboardLoop():
debug("Keyboard Loop Started")
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
thread1 = threading.Thread(target=keyboardLoop)
thread1.start()
time.sleep(2)
Verified this code works normally if I downgrade pynput to 1.6.8
I have the same problem for the combinaison with numpad keys
I have the same problem with the key <255>, so it is confirmed for any keycode, works with 1.6.8
Thank you for your reports.
On what platform is this? It appears that you are trying to implement hot keys; have you tested the global hot key helper included with this library?
I'm on Windows 10, Python 3.9.0
I tried very briefly the hotkey helper, but my hotkey is unusual: ctrl left + ctrl right, and it didn't work (or maybe I gave up too soon) That other method worked under Pynput 1.6.8
I want to note that the other "combination" method doesn't work for me for combinations that include chatacters (eg: including keyboard.KeyCode.from_char('k') in the dictionary) but only for strange combinations such as ctrl left + ctrl right, while hotkey helper works fine for usual hotkeys.