Ubuntu – Turn the Caps Lock LED on, while keep Caps Lock status is off

capslockkeyboard

I have a magicforce smart 68 kb now and it would look better if the Caps Lock LED would emit light too.

I do not even has a Caps Lock function on that button, because I have switched it with the left Control, and made that to be a compose key for the international layout. I was searching and trying some stuff but nothing has worked so far.

tl;dr: How do I turn on the Caps Lock LED without enabling Caps Lock?

Best Answer

  • You can get a list of all controllable LEDs by checking the content of the virtual directory /sys/class/leds:

    $ ls /sys/class/leds/
    input5::capslock  input5::numlock  input5::scrolllock
    

    On my system, there are only the three keyboard LEDs. If your output looks different, make sure you use the correct names instead below!

    Each file is a symbolic link to a directory holding several properties of that LED:

    $ ls '/sys/class/leds/input5::capslock'
    brightness  device  max_brightness  power  subsystem  trigger  uevent
    

    The only thing which is important for us is the brightness file content.

    • 0 means the LED is off.
    • 1 means the LED is on. (Assuming the max_brightness file holds the value 1 - on special keyboards the LED might maybe support multiple brightness values?)

    We get the current LED state by checking the brightness file's content (it's currently off):

    $ cat '/sys/class/leds/input5::capslock/brightness' 
    0
    

    To switch the LED on, we must set that file's content to 1:

    $ echo 1 | sudo tee '/sys/class/leds/input5::capslock/brightness'
    1
    

    To switch the LED on during every boot, you might want to append the command below to your /etc/rc.local script. It will be executed as root, therefore we don't need the sudo tee but can use Bash output redirection:

    $ echo 1 > '/sys/class/leds/input5::capslock/brightness'