I'm looking for a package which allows me to execute a callback any time a key is pressed on the keyboard.
I tried the keyboard package and then I tried pynput the problem is the following: when trying to execute simple code like the following on mac OS Ventura 13.4.1
from pynput import keyboard
import time
def on_press(key):
print('Hello!')
listener = keyboard.Listener(on_press = on_press)
listener.start()
time.sleep(100)
I get Segmentation fault: 11
. The same happens with the other package which works fine on Windows. I read on the issues of the keyboard pakcage that the problem could be related to OS permissions (privacy, accessibility, etc...).
However I tried adding both Vs Code, the terminal, and python to 'trusted' apps and I can't get a simple script to work, any suggestions?