📜  python键盘监控——Python代码示例

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

代码示例1
from pynput.keyboard import Key, Listener

def on_press(key):
    print('{0} pressed'.format(
        key))

def on_release(key):
    print('{0} release'.format(
        key))
    if key == Key.esc:
        # Stop listener
        return False

# Collect events until released
with Listener(
        on_press=on_press,
        on_release=on_release) as listener:
    listener.join()