0

所以我已经成功地能够使用以下代码跟踪鼠标和键盘事件

devices = map(InputDevice, ('/dev/input/event1', '/dev/input/event0'))
devices = {dev.fd: dev for dev in devices}

for dev in devices.values(): print(dev)

while True:
    r, w, x = select(devices, [], [])
    for fd in r:
            for event in devices[fd].read():
                    print(event)

当按下一个键或移动鼠标时,我从这段代码中得到的数据如下:

event at 1550702472.373994, code 00, type 00, val 00
event at 1550702472.389984, code 00, type 02, val -5
event at 1550702472.389984, code 01, type 02, val -2
event at 1550702472.389984, code 00, type 00, val 00
event at 1550702472.405988, code 00, type 02, val -3
event at 1550702472.405988, code 00, type 00, val 00
event at 1550702472.421987, code 00, type 02, val -2

我的问题是如何转换这些数据或分析数字以获得像实际密钥一样的良好输出。类似于分析 1550702472.xxx 数字以获取某个密钥或以下数字。

更新:当我说 print(categorize(event)) 我得到这个:

key event at 1550703468.964836, 38 (KEY_L), down
synchronization event at 1550703468.964836, SYN_REPORT
event at 1550703469.052829, code 04, type 04, val 458767
key event at 1550703469.052829, 38 (KEY_L), up
synchronization event at 1550703469.052829, SYN_REPORT
relative axis event at 1550703472.093778, REL_Y
synchronization event at 1550703472.093778, SYN_REPORT
relative axis event at 1550703472.125780, REL_X
synchronization event at 1550703472.125780, SYN_REPORT
relative axis event at 1550703472.141764, REL_X

仍然是同一个问题,如果 KEY_L 这样做,我可以用什么数组来表示。

4

0 回答 0