NumLock

From LinuxReviews
Jump to navigationJump to search
Keyboard-icon.svg

NumLock is a special key that can be used to turn the number pad on full-size keyboards on and off. You can toggle the NumLock key from software using several simple programs. You can also make it permanently enable the number pad, thereby disabling NumLock.

General XOrg Configuration[edit]

Turning NumLock on/off Using Software[edit]

The ancient and very simple program numlockx lets you turn NumLock on and off. It has very simple options:

numlockx options
option function
on Turn NumLock on (default)
off Turn NumLock off
toggle Change NumLock status (on if off, off if on)
status Check the NumLock status (in case your keyboards indicator light is broken)

You can put numlockx on & in ~/.xinitrc to ensure that NumLock is turned on when you login to your window manager / desktop environment.

Fun fact: The latest numlockx version, 1.2, was written by Lubos Lunak and Oswald Buddenhagen in 2001. It still works like it always has.

Permanently Enabling NumLock[edit]

setxkbmap has an option called numpad:mac that will permanently enable the number pad. If you run

setxkbmap -option numpad:mac

the number pad stays on (NumLock on) regardless of what you do. This option is only for those who want NumLock to be on and stay on and never turn off, ever.

Using The Number Pad As A Mouse[edit]

You can use your number pad in X as a mouse by pressing ⇧ Shift+NumLock. Some distributions disable this feature. See HOWTO use the numeric keyboard keys as mouse in XOrg for the X configuration you need if that's the case and the keys you should press to do mouse clicks and use the number pad as a mouse.

, or . On The Number Pad[edit]

This isn't very related to NumLock but it's slightly relevant: Option "XkbVariant" ",," will make the number pad's comma key output . regardless of what keyboard layout is in play.

File: /etc/X11/xorg.conf.d/00-keyboard.conf
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbVariant" ",,"
EndSection

We do not know why ",," translates to . - it's just the way it is.

Desktop Environments[edit]

Mate[edit]

The Mate desktop environment tries to remember the NumLock status and re-apply it when you login. You can override this with some dconf values. You can set those with:

Turn NumLock On Upon Login
dconf write org.mate.peripherals-keyboard remember-numlock-state false
dconf write org.mate.peripherals-keyboard numlock-state 'on'

Replace numlock-state 'on' with numlock-state 'off' if that is your preference.

Xfce[edit]

Xfce has a value called Numlock for the default Numlock status and RestoreNumlock which decides if Xfce should remember the Numlock status or not in the keyboards channel. Both need the /Default prefix. You can change these settings with xfce4-settings-editor or using xfconf-query in a terminal. You will need to --create RestoreNumlock if you never changed it.

Turn NumLock On Upon Login
xfconf-query -c keyboards -p /Default/Numlock -t bool -s true
Turn NumLock Off Upon Login
xfconf-query -c keyboards -p /Default/Numlock -t bool -s false
Make Xfce remember the Num-Lock setting:
xfconf-query -c keyboards -p /Default/RestoreNumlock -t bool -s true --create

The Linux Kernels Virtual Console[edit]

The simple setleds lets you configure NumLock status in VT TTYs (not X or Wayland). It may sound like it is a program only written to control the LED lights, but it's not.

If you want NumLock on when you login to a virtual terminal (those at ctrl+alt+f1 to ctrl+alt+f12) you can do it by creating a simple script:

File: /usr/local/bin/numlock
#!/bin/bash

for tty in /dev/tty{1..6}
do
    /usr/bin/setleds -D +num < "$tty";
done

and a systemd service that runs that script:

File: /etc/systemd/system/numlock.service
[Unit]
Description=numlock

[Service]
ExecStart=/usr/local/bin/numlock
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Replace +num with -num to always turn NumLock off.


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.