1

Is there a way to turn on the keyboard backlight from the multi-user.target environment? As X11 is not loaded, the command xset led on does not work and gives xset: unable to open display "".

Currently, I am wanting the keyboard backlight to turn on each time the system starts (only if the keyboard is present). I would also like the keyboard backlight to turn on regardless the system loading in a graphical or non-graphical environment. Preferably, I would like this done through Cron.

Bill Joe
  • 11
  • 2

2 Answers2

0

You can do this with setleds, which acts on the current virtual terminal (without using X):

setleds +num +caps +scroll

You can set the VT defaults with the -D flag. If standard input isn’t a VT, you can redirect it:

setleds +num +caps +scroll < /dev/tty1

(assuming you can write to /dev/tty1).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • `setleds +scroll` turned on the keyboard light and the ScrollLock light along with ScrollLock itself. When applying the `-D` flag and rebooting, the VT defaults did not persist as all three were set to off (along with the keyboard light). Writing to `/dev/tty1` did not make this persist either. – Bill Joe Jul 16 '23 at 12:13
  • Ah, are you talking about backlight LEDs rather than the three indicator LEDs? What type of keyboard do you have? (`setleds -D` doesn’t set boot-time defaults, just defaults during the current session.) – Stephen Kitt Jul 16 '23 at 13:53
  • To clarify, I am talking about the backlight LED. I am using the [Cooler Master Devastator II SGB-3031-KKMF1-US](https://www.coolermaster.com/catalog/peripheral/keyboards/devastator-ii/) – Bill Joe Jul 16 '23 at 17:42
0

You need to create a systemd service that starts once upon bootup:

sudo nano /etc/systemd/system/setleds.service

Then type the contents:

[Unit]
Description=Run setleds once at startup
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/bin/setleds +num +caps +scroll
RemainAfterExit=yes
User=root

[Install]
WantedBy=multi-user.target

If that doesn't work and you need the input redirection, just change the relevant line:

ExecStart=/bin/bash -c '/usr/bin/setleds +num +caps +scroll < /dev/tty1'

And to make sure it runs:

sudo systemctl enable setleds.service
sudo systemctl start setleds.service

Alternatively you can use cron instead:

sudo crontab -e

Then, add the following:

@reboot /usr/bin/setleds +num +caps +scroll < /dev/tty1

PS Whoa, I didn't know my keyboard had a backlight... Scroll Lock seems to turn it on!