📜  python 监听键盘输入 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:35.360000             🧑  作者: Mango

代码示例2
# 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