Keyboard backlights for Kubuntu on a MSI Stealth 18 HX AI A2XW

I recently got a refurbished MSI Stealth 18 so I could do a little more intensive AI stuff with the NVIDIA 5090 card.  Setup with Kubuntu for dual boot with Windows 11 was pretty easy (though I’ll post about that next), but there was one little problem — the keyboard backlights didn’t work.

This laptop uses the Steele Series keyboard controllers and allows assigning colors on a per-key basis.  However, the current installation does not have anything about backlights in /sys/class/leds/.  Sigh.  So, F8 (the normal keyboard backlight key) doesn’t work.

The backlights exist at :

$ lsusb | grep -iE ‘steelseries|1038’
ls /sys/class/leds/
Bus 003 Device 002: ID 1038:1122 SteelSeries ApS SteelSeries KLC
Bus 003 Device 005: ID 1038:1165 SteelSeries ApS SteelSeries ALC
enp131s0-0::lan enp131s0-2::lan input3::capslock input3::scrolllock
enp131s0-1::lan enp131s0-3::lan input3::numlock phy0-led

Which tells us:

Device                  USB ID             Function
SteelSeries KLC 1038:1122       Keyboard RGB lighting
SteelSeries ALC 1038:1165       Auxiliary RGB lighting controller

But I can’t talk to it directly.

The default go-to for this is OpenRGB .   They have a nice app for this.  However, this particular MSI box is not supported.  I downloaded it and installed, but it couldn’t find a device.

The next fallback is msi-perkeyrgb  This *does* work.

I had to install the dependencies:

$ sudo apt install git python3-venv libhidapi-hidraw0

Then install:

$ mkdir -p ~/src
$ git clone https://github.com/Askannz/msi-perkeyrgb.git ~/src/msi-perkeyrgb

$ python3 -m venv ~/src/msi-perkeyrgb/.venv

$ ~/src/msi-perkeyrgb/.venv/bin/pip install ~/src/msi-perkeyrgb

My model was not listed under supported models : “~/src/msi-perkeyrgb/.venv/bin/msi-perkeyrgb –list-models”  so I chose GE75 at random.

It worked first time out.

So, I created a little bash script:

#!/bin/bash

sudo ~/src/msi-perkeyrgb/.venv/bin/msi-perkeyrgb \
–id 1038:1122 \
–model GE75 \
–steady ffffff

And that worked fine.

Now, I need to get rid of the need for using sudo:

$ sudo tee /etc/udev/rules.d/70-msi-keyboard-rgb.rules > /dev/null <<‘EOF’
SUBSYSTEM==”hidraw”, KERNEL==”hidraw*”, ATTRS{idVendor}==”1038″, ATTRS{idProduct}==”1122″, TAG+=”uaccess”
EOF

and reload the rules:

$ sudo udevadm control –reload-rules
$ sudo udevadm trigger –subsystem-match=hidraw

So now the script doesn’t need sudo:

~/src/msi-perkeyrgb/.venv/bin/msi-perkeyrgb \
–id 1038:1122 \
–model GE75 \
–steady 00ff00

Now that that’s working, I can add it to the KDE menu.

Install kdialog if necessary:

$ sudo apt install kdialog

Make a directory for my utilities:

$ mkdir -p ~/.local/bin

Now a script that will bring up a color picker and get the numbers:

cat > ~/.local/bin/keyboard-rgb <<‘EOF’
#!/usr/bin/env bash

RGB=”$HOME/src/msi-perkeyrgb/.venv/bin/msi-perkeyrgb”

if [[ ! -x “$RGB” ]]; then
kdialog –error “Cannot find msi-perkeyrgb at $RGB”
exit 1
fi

# Open KDE’s graphical color selector
color=$(kdialog –title “Keyboard RGB” –getcolor) || exit 0

# Remove leading # from HTML-style color
color=”${color#\#}”

# Validate hexadecimal RGB color
if [[ ! “$color” =~ ^[[:xdigit:]]{6}$ ]]; then
kdialog –error “Invalid RGB color: $color”
exit 1
fi

# Apply color to MSI keyboard
if ! output=$(“$RGB” –id 1038:1122 \
–model GE75 \
–steady “$color” 2>&1); then
kdialog –error “Unable to set keyboard color: $output”
exit 1
fi
EOF

chmod +x ~/.local/bin/keyboard-rgb

Now I  can create a Laucher entry so I can choose it from the menu or panel:

mkdir -p ~/.local/share/applications

cat > ~/.local/share/applications/keyboard-rgb.desktop <<EOF
[Desktop Entry]
Type=Application
Name=Keyboard RGB
Comment=Set MSI SteelSeries keyboard backlight color
Exec=$HOME/.local/bin/keyboard-rgb
Icon=input-keyboard
Terminal=false
Categories=Settings;Utility;
EOF

And, finally, add a keyboard shortcut.

Note: the standard

System Settings → Keyboard → Shortcuts  method *does not work* for me in Plasma 6.6.6.  I get the error “”Error while communicating with the global shortcuts service.”.  Instead, I had to do it using the KDE Menu Editor.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.