gpt4 book ai didi

linux - 内核升级后 : missing keyboard events

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:17:50 27 4
gpt4 key购买 nike

内核升级(3.19 到 4.4)后,我的键盘鼠标按钮的按键映射部分损坏。

虽然其他按钮仍按预期工作,但中间按钮只会在按键释放后触发(然后是 keydown 和 keyup)。

测试:

sudo cat /dev/input/event22
sudo evtest /dev/input/event22
sudo showkey

建议?有没有比“/dev/input/event22”更深层次的方法?

最佳答案

最后我得到了一个可行的解决方案:

sudo cat /dev/usb/hiddev0 | hexdump

确实捕获了 keydown/keypress 事件!

我没有深入研究 hiddev API,但识别了每行的计数器前缀和重复后缀值。因为它们在 keydown 和 keyup 之间没有区别,所以我在 python 中实现了一个切换函数(需要对/dev/usb/hiddev0 的读取权限):

import os
import time
import pyautogui as pa

DEVPATH = "/dev/usb/hiddev0"
BTNHEX = "F200A0FF00000000" # first/unique hex value of ThinkPad middle button
NEWKEY = "ctrlleft" # mapping target

def byteToHex(byteStr):
return "".join(["%02X" % ord(b) for b in byteStr]).strip()

def waitForPathExists(DEVPATH):
while not os.path.exists(DEVPATH): time.sleep(0.5)

def watchHandleDev(dev, isPressed):
byteStr = os.read(dev, 8)
currentHex = byteToHex(byteStr[:8])
if currentHex == BTNHEX:
pa.keyUp(NEWKEY) if isPressed else pa.keyDown(NEWKEY)
return not isPressed
return isPressed

def handleDevUnavailable(dev):
print "device '%s' not readable, waiting" % DEVPATH
os.close(dev)
waitForPathExists(DEVPATH)
print "device '%s' found, reopening" % DEVPATH
return os.open(DEVPATH, os.O_RDONLY)

def main():
dev = os.open(DEVPATH, os.O_RDONLY)
isPressed = False
while True:
try:
isPressed = watchHandleDev(dev, isPressed)
except OSError, err:
print "err", err
if err.errno == 5: dev = handleDevUnavailable(dev)

关于linux - 内核升级后 : missing keyboard events,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48238416/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com