Linux监听事件

键盘

https://blog.csdn.net/kcp606/article/details/79859024
https://python-evdev.readthedocs.io/en/latest/tutorial.html
https://www.jianshu.com/p/5f12b0e9a9e5

我的笔记本键盘: /dev/input/event11
我的USB键盘: /dev/input/event10

#!/home/tqc/anaconda3/envs/tf/bin/python
#coding: utf-8
from evdev import InputDevice
from select import select

def detectInputKey():
    dev = InputDevice('/dev/input/event10')
    print(dev)
    print(dev.capabilities(verbose=True))
    while True:
        print('\n')
        select([dev], [], [])
        for event in dev.read():
            print("code:%s value:%s" % (event.code, event.value))


if __name__ == '__main__':
    detectInputKey()

你可能感兴趣的:(Python)