How to set NumLock button to "on" after boot in KDE

For years, the setting of NumLock button in KDE usually does not work. If you set it to “on” in

System Settings -> Input Devices -> Keyboard

then this setting most likely will be ignored, and after boot the user has to press that button on the keyboard to have NumLock on. This is bothersome if the password to login contains numbers.

Google helped to find a solution. If SDDM is used for login screen, which is the default, then add these lines in file

/etc/sddm.conf

which is likely empty:


[General]
Numlock=on

KDE is only involved after you typed your password.

For completeness, for virtual consoles you need a different strategy, this works fine:

# systemctl edit getty@.service 
# # input the next two lines
[Service]
ExecStartPre=/bin/sh -c 'setleds -D +num < /dev/%I'
# # save

Attempt on tty2 (tty1 is already up so it needs a restart).

Source: https://wiki.archlinux.org/index.php/Activating_numlock_on_bootup#Console

Don’t tinker. NumLock is set in the bios. System Numlock is set in /etc/sysconfig/keyboard and can be changed using “yast2 sysconfig”.

## Type:        list(bios,yes,no)
## Default:     bios
#
# NumLock on? ("yes" or "no" or "bios" for BIOS setting)
# This setting may interfere with GNOME /org/gnome/settings-daemon/peripherals/keyboard/remember-numlock-state DConf key.
KBD_NUMLOCK="bios"

In my experience, I had to tinker too. There’s no NumLock setting in BIOS, and I don’t recall the issue being fixed by setting to “yes”. I may have done it wrong somehow though, as I was trying to get it working mostly for the graphical session. Later I discovered that in vt’s the numpad wouldn’t work (no numlock key).


# sudo rg --line-number -w '(/etc/sysconfig/keyboard|setleds)' /usr
/usr/sbin/kbdsettings:3:    . /etc/sysconfig/keyboard
/usr/sbin/kbdsettings:19:            /usr/bin/setleds -D +$param < /dev/$tty
/usr/sbin/kbdsettings:25:            /usr/bin/setleds -D -$param < /dev/$tty
/usr/sbin/kbdsettings:32:                    /usr/bin/setleds -D +$param < /dev/$tty
/usr/sbin/kbdsettings:35:                    /usr/bin/setleds -D -$param < /dev/$tty
 

/etc/sysconfig/keyboard is used to source this routine, and we can see it uses the setleds above for a given tty.


## Path:        Hardware/Keyboard
## Description: Keyboard settings for the text console
## ServiceRestart: kbdsettings
#

...

## Type:        list(bios,yes,no)
## Default:     bios
#
# NumLock on? ("yes" or "no" or "bios" for BIOS setting)
# This setting may interfere with GNOME /org/gnome/settings-daemon/peripherals/keyboard/remember-numlock-state DConf key.
KBD_NUMLOCK="bios"

...

## Type:        string
## Default:
#
# ttys for the above settings 
# Example: "tty1 tty2"
# "" for tty's 1-6
#
KBD_TTY=""



It shouldn’t have anything to do with X. Are you positive it works for X, and if so, have you set KBD_TTY to include tty7? On X it fails to call setleds, or more precisely, to open /dev/tty7.

KBD_NUMLOCK overrides bios, plasma settings override KBD_NUMLOCK. tty1…6 default to numlock=no and may be changed in /etc/sysconfig/keyboard. X11 checks for file numlock-on which is created or deleted by /usr/sbin/kbdsettings. Settings are:

karl@erlangen:~> localectl
   System Locale: LANG=de_DE.UTF-8
       VC Keymap: de-latin1-nodeadkeys
      X11 Layout: de
       X11 Model: pc105
     X11 Variant: nodeadkeys
     X11 Options: terminate:ctrl_alt_bksp
karl@erlangen:~> 

Thanks, it’s indeed a better solution, as it fixes for both consoles and Xorg. I’ll propose changing the docs for /etc/sysconfig/keyboard to include that Xorg picks it up too, not just text consoles. Do you think it makes sense? I feel somewhere in the Xorg docs should mention this as well, but have no idea where.

Thanks! It’s just what I needed for Fedora on my UEFI installations.

If plasma has no way of inheriting/using the current value of KBD_NUMLOCK then someone should file an issue with Plasma IMHO…

System Settings > Input Devices > Keyboard > NumLock on Plasma Startup has:

  1. Turn on
  2. Turn off
  3. Leave unchanged

With this much knowledge, can somebody write a small manual

“How to have NumLock on always, no matter how the booting is done and at what level opensuse runs”?

Yes, are you offering to do that? Take a look how to write an SDB article in the wiki: https://en.opensuse.org/Portal:Support_database

No. I don’t understand most of the discussion. I can only contribute in a small part - in editing the sddm.conf.

There is already a section on configuring the keyboard: https://doc.opensuse.org/documentation/leap/startup/html/book-opensuse-startup/cha-yast-hw.html#sec-yast-hw-keym

Unfortunately it’s too short and inaccurate. Section 3 should be deleted as “Expert Settings” are no longer available. Add at the end of the section:

The following settings may be changed using yast2 > sysconfig > hardware > keyboard:

  • Repeat Rate
  • Delay before Repetition Starts
  • Start-up States for Num Lock, Caps Lock, and Scroll Lock
  • Devices on which the values for Num Lock, Caps Lock, and Scroll Lock should be set
  • Disable Caps Lock

I clicked “Edit source” but learned a fork was needed to propose changes to the documentation. When I looked further it says it would apply to SLE but the documentation says it applies to Leap 15.2. I am left confused.

The pull request template says ( https://github.com/SUSE/doc-sle/blob/master/.github/PULL_REQUEST_TEMPLATE.md ):

We are currently only merging documentation relevant for SLE 15 SP2 (and Leap 15.2) or lower.