This is the same question as in Change keyboard locks in Python or How to change caps lock status without key press.

But there is a difference!!

I don't want to change the lights on /dev/console or /dev/tty but on a human interface device that is connected via USB and recognised as /dev/hidraw0.

To make it even harder, this is being used on a Raspberry Pi.

The method suggested in the other questions doesn't work.

1

There are 1 best solutions below

1
On

Using library at Jakub Wilk's library at http://jwilk.net/software/python-keyboardleds, it is pretty simple:

lk = LedKit('/dev/input/event1')
lk.num_lock.reset()
lk.caps_lock.reset()

The trick is to determine which input device your keyboard is. To figure that out, you look at /proc/bus/input/devices. (Thanks to Jakub for this solution)

I tested this on two a keyboards:

  1. PS1 keyboard connected via PS1 to USB adaptor with Holtek chipset (04d9:1400)
  2. A cheap numeric keypad, also with Holtek chipset (04d9:1603), HT82M99E.

Result: It works for the former but not the latter.

Perhaps someone knows whether that's a driver issue or a problem of the hardware itself (not responding to requests from the driver).