Description
The Numpad numbers does not work in HotKeys.
Platform and pynput version
Windows 7;pynput 1.7.6
To Reproduce
I tried to use the Numpad to respond to the shortcut, but he didn't work
Here is my code:
from pynput import keyboard
def on_activate_h():
print('hotkey pressed')
with keyboard.GlobalHotKeys({
'<97>': on_activate_h, }) as h:
h.join()
I found his method in pynput.keyboard.HotKey.press
def press(self, key):
if key in self._keys and key not in self._state:
self._state.add(key)
if self._state == self._keys:
self._on_activate()
I added some test statements:
def press(self, key):
print('pressed: ', key, type(key))
for i in self._keys:
print('check: ', i, type(i))
print('is pressed = key: ',key==i)
if key in self._keys and key not in self._state:
self._state.add(key)
if self._state == self._keys:
self._on_activate()
Why does <97> ! = <97>
I tried converting that KeyCode key to str, which solved the problem:
def press(self, key):
print('pressed: ', key, type(key))
for i in self._keys:
print('check: ', i, type(i))
print('is str(pressed) = str(key): ',str(key)==str(i))
So this code, if modified as follows, can accomplish my purpose, but does this result in an unintended error?
def press(self, key):
keys_str = [str(i) for i in self._keys]
if str(key) in keys_str and key not in self._state:
self._state.add(key)
if [str(i) for i in self._state] == [str(i) for i in self._keys]:
self._on_activate()
Description The Numpad numbers does not work in HotKeys.
Platform and pynput version Windows 7;pynput 1.7.6
To Reproduce I tried to use the Numpad to respond to the shortcut, but he didn't work Here is my code:
I found his method in pynput.keyboard.HotKey.press
I added some test statements:
The following issues were identified:
Why does <97> ! = <97> I tried converting that KeyCode key to str, which solved the problem:
So this code, if modified as follows, can accomplish my purpose, but does this result in an unintended error?
Will you fix it?