If you can wait a day or two, I'll add this functionality to python-evdev and update this answer. It's probably going to look something along the lines of:
from evdev import InputDevice, ecodes
dev = InputDevice('/dev/input/eventX') # your keyboard device
dev.ledstates(verbose=True)
{ (0, 'LED_NUML') : True,
(1, 'LED_CAPSL') : True,
(2, 'LED_SCROLLL') : False}
Using xset
, as mentioned by @ronak, is a lot easier since you don't have to have read permissions on any input devices. Unfortunately, it works only under X (and X in turn uses the evdev
interface (at least on linux)).
Well, It took me long enough, but it's in. The interface for getting 'ON' LEDs ended up being:
>>> dev.leds()
[0, 1, 8, 9]
>>> dev.leds(verbose=True)
[('LED_NUML', 0), ('LED_CAPSL', 1), ('LED_MISC', 8), ('LED_MAIL', 9)]
Getting all available LEDs on a device:
>>> dev.capabilities()[ecodes.EV_LED]
[0, 1, 2]
>>> dev.capabilities(verbose=True)[('EV_LED', ecodes.EV_LED)]
[('LED_NUML', 0), ('LED_CAPSL', 1), ('LED_SCROLLL', 2)]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…