Python3 监控键盘输入

pynput.keyboard监控键盘输入

from pynput.keyboard import Key, Controller, Listener

keyboard = Controller()


# 点击按钮
def on_press(key):
    print('{0} 被按下'.format(key))


# 释放按钮,按esc按键会退出监听
def on_release(key):
    print('{0} 被释放'.format(key))
    if key == Key.esc:
        return False


# 创建监听
with Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()

Python3 监控键盘输入_第1张图片

你可能感兴趣的:(Python,3,python)