I can read the NUML_LED state using evdev. But if I grab() the device after reading the leds when I exit the program the led is off even though the state is still on as far as the system is concerned.
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
If I just do one of grab()
OR device.leds()
without the other they (as expected) don't turn off. But invoking both messes with the leds.
Edit: I just realised that if LED_NUML and LED_CAPSL are on when I exit the leds are off but when I press either num_lock or caps_lock the state of the other button gets fixed also.
IE:
- 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
At this time it is not possible. There is an issue in the kernel. As ssieb says on the python evdev issues page 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.