在Windows 10和Python 3.7中使用pynput,返回的字符代码反映了程序启动时大写锁定键的状态。对该键的更改不会导致返回值的更改。
from pynput import keyboard
def on_release(key):
print('{0} released'.format(key))
if key == keyboard.Key.esc:
# Stop listener
return False
with keyboard.Listener(on_release=on_release) as listener:
listener.join()
在使用大写锁定的情况下运行时,我得到:
'A' released
Key.caps_lock released
'A' released
Key.esc released
Aa
>>>
因此,大写锁定已关闭。重新启动,我得到
=== RESTART: C:/Users/davec/Documents/Perkins/Browser/tests/pynput-kbd.py ===
'a' released
Key.caps_lock released
'a' released