Linux监听事件

版权声明:本文纯属作者口胡,欢迎转载 https://blog.csdn.net/TQCAI666/article/details/86213853

键盘

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()

猜你喜欢

转载自blog.csdn.net/TQCAI666/article/details/86213853