我正在使用Pynput键盘模块来检测python应用程序中的击键。
目前我无法区分数字键盘键和常规数字键,它们都返回为“ 1”,“ 2”,“ 3”等
那我想念什么?
代码:
def on_press(key):
print key
def on_release(key):
return
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
答案 0 :(得分:1)
您可以使用vk
对象的key
属性获得virtual key code,对于从数字键盘键输入的数字,其范围是96到105:
from pynput import keyboard
def on_press(key):
if hasattr(key, 'vk') and 96 <= key.vk <= 105:
print('You entered a number from the numpad: ', key.char)
with keyboard.Listener(on_press = on_press) as listener:
listener.join()