2

Using pynput with Windows 10, Python 3.7, the character code returned reflects the state of the caps lock key when the program was started. Changes to that key do not lead to changes in the value returned.

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()

When this is run with caps lock on I get:

'A' released
Key.caps_lock released
'A' released
Key.esc released
Aa
>>> 

So the caps lock is now off. Restarting, I get

=== RESTART: C:/Users/davec/Documents/Perkins/Browser/tests/pynput-kbd.py ===
'a' released
Key.caps_lock released
'a' released
David C
  • 21
  • 3

0 Answers0