Open whaleymar opened 1 year ago
I think I found the source of the issue. I added a breakpoint in the HotKey.press
method and see that the key
arg has a _scan
attribute of 82 (the scan code for numpad 0), but in self._keys
the _scan
attribute is None
. For some reason, numpad numbers and decimal are the only keys I've seen with scan codes, even though they exist for most keys...
as a workaround, I added this as the first line in HotKey.press
:
setattr(key, '_scan', None)
If anyone can point me towards the correct way to fix this I can submit a PR
Over year later and the issue is still there. I did the same workaround as you but in a way that does not require modifying the pynput source code. In the sample code provided in first post I have changed the for_canonical
method (which is also an example from docs) as follows:
def for_canonical(f):
return lambda k: (setattr(k, '_scan', None), f(listener.canonical(k)))
Description I would like to create a hotkey using the numpad, but numpad 0-9 and decimal cannot trigger hotkeys.
Platform and pynput version Windows 10, pynput 1.7.6
Code to reproduce the issue
Actual vs Expected Output (after pressing numpad 0) Actual:
Expected:
The same behavior occurs for numpad 0-9 (keycodes 96 - 105) and decimal (110). I have not exhaustively tried all keycodes. I have confirmed that this code does perform as expected if I used keycodes 112 - 123 (F1-F12).