device.leds() 后的 grab() 关闭 LED

grab() after device.leds() turns off led

我可以使用 evdev 读取 NUML_LED 状态。但是,如果我在退出程序时在读取 LED 后抓取()设备,即使就系统而言状态仍处于打开状态,LED 也会关闭。

import evdev

device = evdev.InputDevice('/dev/input/event3')

try:
    print(device.leds(verbose=True))
    print("Using device:\n" + str(device))
    device.grab()
except  (KeyboardInterrupt, SystemExit):
    pass

如果我只执行 grab()device.leds() 中的一个而不执行另一个,它们(如预期的那样)不会关闭。但是同时调用 LED 会造成混乱。

编辑: 我刚刚意识到,如果 LED_NUML 和 LED_CAPSL 在我退出时亮起,则 LED 熄灭,但是当我按下 num_lock 或 caps_lock 时,另一个按钮的状态也会得到修复.

即:

- LED_NUML and LED_CAPSL are on
- run script
- LED_NUML and LED_CAPSL are off
- press num_lock turns num_lock off (LED_NUML is already off so it stays off)
- LED_CAPSL turns on

目前还不能。内核有问题。正如 ssieb 在 python evdev 问题页面 about this issue.

上所说

When a device is released, all handlers attached to the device get restarted. My guess is that there is some handler that is resetting the LEDs.