📅  最后修改于: 2022-03-11 14:45:35.360000             🧑  作者: Mango
# For windows
from pynput import keyboard
def on_press(key):
try:
k = key.char # single-char keys
except:
k = key.name # other keys
print('Key pressed: ' + k)
return False # stop listener; remove this if want more keys
listener = keyboard.Listener(on_press=on_press)
listener.start() # start to listen on a separate thread
listener.join() # remove if main thread is polling self.keys