How to set numlock ON at boot into kiosk mode

Hello, I am using DietPi kiosk Chromium mode which is working fine. But when device boots numlock is OFF which is confusing for users as they need input numbers. Is there any simple way to enable numlock at boot? I found tutorials on internet but they only works with full desktop environments or I don’t know how to apply them on kiosk mode.

For example:
root@dietpi:~# numlockx
Error opening display!

numlockx works within an X environment only. Probably it can be passed with the X startup scripts, not sure.

Which hardware is it? On x86 systems there may be a numlock switch in BIOS/UEFI settings.

Ah found a way:

echo -e '#!/bin/dash\nsetleds -D +num < /dev/tty1' > /var/lib/dietpi/postboot.d/enable-numlock.sh

This enables the numlock for TTY1 (default login console) once on boot and changes the default for this boot session as well so that any reset will leave the numlock enabled. I haven’t tested yet, but it should work.

Thanks for idea, I’ll try tomorrow. Hardware is Raspberry Pi 4 2GB and keyboard is standard cheap USB connected.

Nah, it’s not working. :frowning: NumLock LED on keyboard is lit after boot but user cannot type numbers on keypad - NumLock functions like it is still OFF. Only when I press NumLock on keyboard (LED stays lit) it starts to work - user can type numbers on keypad.

Hum, probably it’s somehow not taken by the X environment. Does it work when exiting Chromium and typing numbers via numpad to console?

The command sounds like it’s about the LED only (not the function) but I remember a similar command in Windows where indeed LED and keypad are tied strictly.

Actually this answer indeed indicates that it has to be configured for X separately, nasty: boot - Enable num-lock as default in Linux - Unix & Linux Stack Exchange

I’ll try to find an xorg.conf setting when I find time.

EDIT: Actually the numlockx package installs an X session hook/script. Can you check /etc/default/numlockx whether it can be enabled there?

Yes, when I kill chromium-browser, numlock is enabled and I can input numbers in console with your setleds script.
I tried setting auto, on, toggle in /etc/default/numlockx but nothing worked.

My working naive solution is

 /var/lib/dietpi/postboot.d/enable-numlock.sh
#!/bin/bash

while ! pidof chromium-browser >> /dev/null ;
do
sleep 1
done

export DISPLAY=:0 && export XAUTHORITY="/home/dietpi/.Xauthority" && xdotool key Num_Lock
1 Like