Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

HowTo: Customize RGB keyboard backlight color per key #204

Closed
def-user opened this issue Nov 24, 2023 · 0 comments
Closed

HowTo: Customize RGB keyboard backlight color per key #204

def-user opened this issue Nov 24, 2023 · 0 comments

Comments

@def-user
Copy link

Actually this isn't a question for help, but already an answer for those, who try to figure out how to do this. Below you can find some bash commands to apply various colors to definable keys backlight.
TLDR: see section COMMANDS below

First look if tuxedo-keyboard is installed correctly:

lsmod | grep tuxedo

The output should look like this:

tuxedo_io              24576  1
tuxedo_keyboard        94208  3 clevo_acpi,tuxedo_io,clevo_wmi
led_class_multicolor   16384  2 ite_829x,tuxedo_keyboard
sparse_keymap          12288  2 intel_hid,tuxedo_keyboard

Maybe you have to install tuxedo-control-center, too, to make everything work. In every case you need to reboot after installing the modules. The next command should give a long list of directories with the following name
syntax, where # is a number from 1 to 119 (or even 126):

ls /sys/class/leds/ | grep rgb

Output:

...
rgb:kbd_backlight_#
...

If so, good. If not, the driver is probably not working correctly. You may have to remove and reinstall it.
Every single of those directories stands for one single LED triplet (here shortened: tripLED)
underneath your keyboard keys, except for some, that don't. The latter are just there to fill the gaps to have a more or less consistent row and column numbering scheme, I guess.
There is one directory without '_#' suffix, which is the ESC-key in my case, but if you'd ask me, it should have suffix '_0' to have it consistent.

Here follows the numbering scheme for my 17" notebook keyboard with a numblock and scroll keys above, where [# #] stands for 'grouped under the same key':

 NAN   1   2   3   4   5  6   7   8  9  10  11  12  13  14  15    | 16  17  18  19
  20   21  22  23  24  25  26  27  28  29  30  31   33 [34  35]   | 36  37  38  39
 [40 41] 42  43  44  45  46  47  48  49  50  51  52  53   [54 \   | 56  57  58  59
 [60  61] 62  63  64  65  66  67  68  69  70  71   72   74  \75]  | 76  77  78  79
  80    82  83  84   85  86  87  88  89  90  91  92  [93 94]  95  | 96  97  98  99
[100 101]102 103 104[105           109] 110 111 [112 113] 114 115 116 |117 118 119

numbers without counterpart are in my case:
0, 32, 55, 73, 81, 106..108

The content of one directory should look like this:

# ls /sys/class/leds/rgb:kbd_backlight_1/
brightness  device  max_brightness  multi_index  multi_intensity  power
subsystem  trigger  uevent

The only two/three files of interest are:

  • multi_intensity
  • brightness
  • (max_brightness)
max_brightness

stores a single number which gives the maximum number to
be set in 'brightness'. I wouldn't change this.
Default: 10

multi_intensity

stores the RGB value in three decimal numbers from 0 to 255,
seperated by a single space.
Default: 0 0 255


And finally

THE COMMANDS

Here follows a list of possible commands to permanently change the color of the keyboard's backlights. NOTE: your key mapping might be different. If the commands are not working like expected you have to figure out your personal mapping by trial and error with the second command.

1. Changing the whole keyboards backlight color at once:

echo '0 150 255' | sudo tee /sys/class/leds/rgb:kbd_backlight*/multi_intensity

2. Changing a single tripLED's/key's color (two examples):

echo '255 0 155' | sudo tee /sys/class/leds/rgb:kbd_backlight_15/multi_intensity
echo '255 0 155' | sudo tee /sys/class/leds/rgb:kbd_backlight/multi_intensity

Your DEL and ESC keys should be pink now.

3. Applying a blueish green to all the function keys and the Fn key:

for i in {1..12} 102;do echo '0 255 80' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity; done

4. Color the num block and keys above in yellow (two examples):

for i in {16..19} {36..39} {56..59} {76..79} {96..99} {117..119};do echo '255 150 0' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity; done
for i in {16..96..20} {17..117..20} {18..118..20} {19..119..20};do echo '255 150 0' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity; done

5. Color the arrow keys in the same green like the function keys in step 3:

for i in 95 {114..116};do echo '0 255 80' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity; done

6. Applying random colors to every second key (including the ESC key):

for i in {2..119..2} '\b*';do echo `shuf -i 0-255 -n 3` | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity; done

NOTE the accents `` around the 'shuf' command, which return the output of the code inside executed in a sub-shell.

7. Applying a color gradient to the function keys:

for i in {1..12};do echo $(((i-1)*22)) $(((12-i)*14)) $(((12-i)*9+156)) | sudo tee /sys/class/leds/rgb\:kbd_backlight_$i/multi_intensity; done


complete template script

If you put steps 1 to 5 in an executable script, you'd have some kind of layout template to work with. Sometimes you have to reactivate it. For me suspend deactivates backlight at all and I have to run the script again.

#!/bin/bash
# keyboard backlight script by def-user

# all keys
echo '0 150 255' | sudo tee /sys/class/leds/rgb:kbd_backlight*/multi_intensity

# DEL key
echo '255 0 155' | sudo tee /sys/class/leds/rgb:kbd_backlight_15/multi_intensity

# ESC key
echo '255 0 155' | sudo tee /sys/class/leds/rgb:kbd_backlight/multi_intensity

# function and Fn keys
for i in {1..12} 102;
do
    echo '0 255 80' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity
done

# complete numblock and keys above
for i in {16..19} {36..39} {56..59} {76..79} {96..99} {117..119};
do
    echo '255 150 0' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity
done

# arrow keys
for i in 95 {114..116};
do
    echo '0 255 80' | sudo tee /sys/class/leds/rgb:kbd_backlight_$i/multi_intensity
done

You may want to alter the first line and put in the path to your bash install given by:

which bash

Don't forget to make it executable via:

chmod u+x keyboard_backlight_layout.sh

The changes should be persistent through reboots, so there is no need to autostart the script.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant