2

在 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
4

0 回答 0