There has been a similar question – but IMHO there has to be a simpler solution. If num-lock is on in the BIOS – why is it turned off during linux boot and/or KDE/Gnome/whatever startup?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Linux initializes most peripherals so that they’ll be in a known state. This includes the keyboard: Linux’s internal data about the keyboard had better match the LEDs, so what Linux does is to turn off the LEDs (as far as I recall, the CPU can’t read the state of the LEDs on a PC keyboard) and declare all *Lock to be off.
I like to have NumLock on by default. For Linux text consoles, what I used to do¹ is to run
for t in /dev/tty[0-9]*; do setleds -D +num <$t; done
from a boot script (/etc/rc.local or /etc/init.d/50_local_setleds or wherever the distribution likes to put those).
Nowadays, at least on some distributions such as Debian, you can add LEDS=+num to /etc/console-tools/config (or /etc/kbd/config depending on which one you have).
The X window system has its own keyboard handling, so you need to deal with it separately. What I do is to switch caps lock permanently off (I don’t have a Caps Lock key in my layout) and switch num lock permanently on (I don’t have a Num Lock key in my layout, and the keypad keys send KP_1 and so on). If you want to retain the modifiers but make Num Lock default on, you can write a small program to call XKbLockModifiers to set the modifier inside X and XChangeKeyboardControl to set the physical LED.
¹ Used to, because I haven’t bothered with text consoles in a while.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0