I’m trying to catch keystrokes in a python script, but it ONLY catches modifier keys (ctrl, cmd, alt) and not ordinary alphanumerical keys. Running on Mac Sonoma 14.1.1, Python 3.10.6.
from pynput.keyboard import Key, Listener
def on_press(key):
try:
print(f'nYou Entered {key.char}')
except AttributeError:
print(f'nYou Entered {key}')
if key == Key.delete:
# Stop listener
return False
# Collect all event until released
with Listener(on_press=on_press) as listener:
listener.join()
The output I get is:
You Entered Key.cmd
You Entered Key.alt
t
e
s
t
You Entered Key.cmd
You Entered Key.alt
Ie, it’s not registering the normal keys. Same problem with using the import keyboard
but with the following error:
ValueError: ("Key 's' is not mapped to any known key.", ValueError('Unrecognized character: s'))