I have standard keyboard with numerical keys on the right side (I guess it's called 104-key keyboard). I want to use the numerical keys only as numerical keys. That means, I don't want the NumLock to switch on and off the numerical keys.

However, sometimes it happens (I don't know how, perhaps by me accidentally hitting the NumLock key) that the numlock is turned off, and I have to press it again. This is extremely annoying.

Is it possible to disable switching off numlock?

In other words: I want my numerical keys to always act as number keys, and to disable the numlock switch.

I am using Debian and LXDE (Openbox).

  • There is this thread: ubuntuforums.org/showthread.php?t=2138114 – slm Nov 9 '13 at 6:23
  • @MartinVegter Would you like to post here the contents of ~/.config/openbox/autostart and ~/.config/openbox/rc.xml? – Risto Salminen Dec 1 '13 at 10:15
  • Need an event, which will trigger the Numlock off again if it detected that numlock is ON. Disabling numlock is as easy as mentioned by xmodmap. Only question left is how to get that event......? – SHW Jun 24 '14 at 10:04

13 Answers 13


After reading all the answer here I was quite surprised to see that you can do the following.

<keybind key="Num_Lock">
  <action name="Execute">
    <command>numlockx on</command>

So every time you press Num, which deactivates the numlock. It will execute numlockx on, which reactivates numlock.

The name comes from my output of xev which gave me the key code 77 and the name Num_Lock

In @MartinVegters case he needed to wait a few seconds so the numlockx on definitely gets executed after the event of Num is handled. Since there is a race condition between the handling of numlock in the kernel and the execution numlockx.

For this case you can write a small script denumlock.sh like


sleep "$1"
numlockx on

and use it in the Key binding

<command>/bin/sh denumlock.sh 1</command>

This is dirty but it works.

What I recommend is the following which I couldn't test myself. You better follow the first answers which suggest to use

xmodmap -e 'keycode 77 = Escape'

But for LXDE you need to use the LXDE autostart mechanism which is different from the Openbox way of editing the ~/.config/openbox/autostart.

In LXDE you apparently need to edit ~/.config/lxsession/LXDE/autostart or with Lubuntu ~/.config/lxsession/Lubuntu/autostart, which holds the commands for the start up. (See Arch docs and LXDE docs) You may need to create that file and add this line.

@xmodmap -e 'keycode 77 = Escape'

Sadly, as I said I cannot test if this works, since I only have a VM running with LXDE.

  • 1
    I have tried your solution <keybind key="Num_Lock"> but unfortunately it does not work. While the command numlockx on gets executed, <kbd>NumLock</kbd> still retails its function as numlock. So I can still switch numlock on/off. – Martin Vegter Jun 24 '14 at 11:55
  • As to the other solution, using xmodmap, when I tried the solution suggested by Risto Salminen, the command worked, but I have lost all my key bindings. – Martin Vegter Jun 24 '14 at 11:57
  • @MartinVegter Mhh you could try a sleep 3; numlockx on for the key bind. For the second solution have you tried it with the autostart? – Raphael Ahrens Jun 24 '14 at 12:10
  • I don't understand why, but even sleep 3; /usr/bin/numlockx on does not work. NumLock still acts as a on/off switch. – Martin Vegter Jun 24 '14 at 12:17
  • @MartinVegter does /usr/bin/numlockx on work on your system? – Raphael Ahrens Jun 24 '14 at 12:18

perhaps by me accidentally hitting the NumLock key

If the keyboard is yours (rather than your employer's for example), just remove it from the keyboard physically.

You can still press it with a pointy thing if you ever really need to.

enter image description here

  • 4
    Yeah, +1. Simple is elegant. – ypercubeᵀᴹ Jun 24 '14 at 13:29
  • 1
    sadly my NumLuck's default state is the wrong one :( – MichaelChirico Sep 2 '15 at 19:46

On my laptop keyboard (Ubuntu 10.04) keyboard lock is currently On.

$ xmodmap -pke|grep 77
keycode  77 = Num_Lock Pointer_EnableKeys Num_Lock Pointer_EnableKeys
keycode 177 = XF86Phone NoSymbol XF86Phone
$ xmodmap -e "keycode 77 ="

Voila ! numlock is now disabled.

xmodmap -e "keycode  77 = Num_Lock Pointer_EnableKeys Num_Lock Pointer_EnableKeys"

Puts it back again. (Maybe greping for Num_lock would have been a better idea, but you get the gist).

Reply to @Martin Vegter's comment.

Ok, in reply to your comment xmodmap ruins your bindings, understood.

I have just checked the Openbox Documentation

Take a look in ~/.config/openbox/lxde-rc.xml

ls -l lxde-rc.xml (do you have an rc.xml as well ?, please check ).

take a copy of it as backup

(use an editor) search for numlock (maybe nmlk).

Do you see something like this ?

<keybind key="Numlock">
<action name="whatEverItSays"/>

Comment it out OR change The keybind key-value to an alternative eg Alt-Numlock to toggle



To Comment out

<!-Commented out from here
    <keybind key="Numlock">
    <action name="whatEverItSays"/>
To Here -->


Change to Alt+Numlock toggle

<keybind key="A-Numlock">
  <action name="whatEverItSays"/>

save changes and logout/login or restart.

  • The problem is, any xmodmap command (i.e. xmodmap -e 'keycode 77 = Escape') destroys my existing key-bindings which are defined in .config/openbox/lxde-rc.xml – Martin Vegter Nov 11 '13 at 13:02
  • 1
    I have replied above to obtain better formatting. – X Tian Nov 11 '13 at 14:00
  • thanks for your reply. However, in my .config/openbox/lxde-rc.xml, there is no line containing Numlock or Num_Lock. When I create one, it has no effect: <keybind key="Num_Lock"> <action name="Execute"> <command>/bin/true</command> </action> </keybind> – Martin Vegter Nov 11 '13 at 14:44
  • 1
    There must be another config file being read before the one in your home directory. two places I suggest looking, /etc/xdg/openbox and /usr/share/... If this is no help, I'll need to give up - sorry. – X Tian Nov 11 '13 at 14:59
  • from 3.4.7 changed log (openbox) "Fix key bindings getting lost if multiple bindings at the same level could not be translated (Fixes VMWare causing Openbox keybindings to stop working)" – X Tian Nov 11 '13 at 17:06

Find your numlock keycode with xev. For example, here, Num_Lock is 77.

Use xmodmap to remap the keycode:

  • For current X sessions, inside a shell, use xmodmap -e 'keycode 77 = '.
  • To all future X sessions, inside ~/.xprofile place xmodmap -e 'keycode 77 = '.

    EDIT: Note: Doesn't work if a software is changing the Num Lock state.

  • 1
    The command xmodmap -e 'keycode 77 = ' works, but it causes a serious problem: all my key-bindings stop working – Martin Vegter Nov 7 '13 at 9:17
  • Well, you can attempt to map it to a valid, harmless key. Like xmodmap -e 'keycode 77 = Escape' (YMMV, ESC seems safe for me). Do you have a ~/.Xmodmap file? If yes, instead of ~/.xprofile, place the keycode 77 = Escape at the end of this file. – emp.justine Nov 10 '13 at 8:22
  • 1
    The problem is, any xmodmap command (i.e. xmodmap -e 'keycode 77 = Escape') destroys my existing key-bindings which are defined in .config/openbox/lxde-rc.xml – Martin Vegter Nov 11 '13 at 12:50

pic of keyboard optionswith LinuxMint 17.2 and I imagine other versions of Ubuntu you can go to your KEYBOARD setting and then LAYOUTS on that page you will find a small "options" button.

From there go to "misc compatibility options" and check "numberic keys always enter digits"

This is a lifesaver for me. It bugs the heck out of me to type a number and be moved somewhere else on the page. Cheers! ;)

  • 1
    This answer should have much more points! – Carlos Gant Aug 31 '17 at 8:38
  • This can be done also from command line by setxkbmap -option numpad:mac or by setting Option "XkbOptions" "numpad:mac" in xorg.conf. – j123b567 May 29 '19 at 7:06

Just remove the NumLock key mapping by mapping it to nothing: first run xev and press Num Lock (it will probably print 77), and then run the command:

xmodmap -e "keycode # = """

where # is the keycode of NumLock.

You'd also put this to ~/.xprofile to disable NumLock in x sessions.

  • In case my original question is not clear: I don't want to turn off numlock. I want the opposite. I want to ensure that it cannot be turned off (I want numlock always on) – Martin Vegter Nov 6 '13 at 11:03
  • Ah, I obviously had an error in my thinking, thanks for letting me know. :) I'll see if I can improve my answer. – Risto Salminen Nov 6 '13 at 11:10
  • this has no effect on my system: xmodmap -e "remove Lock = Num_Lock" – Martin Vegter Nov 7 '13 at 9:17
  • Now the command works, but it destroys all my key-bindings. All key-bindings stop working. – Martin Vegter Nov 7 '13 at 11:37
  • Well, it shouldn't, according to this answer on superuser. – Risto Salminen Nov 7 '13 at 11:56

Other answers here suggested using numlockx on with xmodmap -e 'keycode 77 =', but numlockx on wouldn't work on my system together with that xmodmap command, showing me an error message:

$ numlockx on
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  132 (XTEST)
  Minor opcode of failed request:  2 (X_XTestFakeInput)
  Value in failed request:  0x0
  Serial number of failed request:  17
  Current serial number in output stream:  20

And also setting xmodmap -e 'keycode 77 =' would for some reason remove all my keybindings made with xbindkeys.

This answer to a similar question has helped me, however. Part of my ~/.xinitrc:

numlockx on
xmodmap -e 'keycode 77 = NoSymbol Num_Lock'

This way the NumLock does nothing by itself, but if pressed with Shift it serves its original (mostly useless) purpose, and most importantly it doesn't prevent numlockx on from working on my system, or mess up my xbindkeys key bindings.


Another way, if you want to disable the numlock key disable permanently. You can do so by modifying your current keymap file by modifying the keycode 77.

Set this value to "none", so that accidental press the key will do nothing.

Use numlockx at bootup to start it and use the modified keymap file in one of starting script e.g. ~/.bashrc or in /etc/profile.

NOTE: I haven't tested this, but it should work.


On OpenSuse 13.x with KDE, this worked for me:

  • install numlockx
  • Add Custom Shortcut:
    • Custom Shortcuts -> Edit -> New -> Global Shortcut -> Command/URL:
    • Action Name: NumLockOn
    • Comment: Keep numlock on
    • Trigger: set to NumLockk
    • Action-> Command/URL: sh -c 'sleep 0.5;numlockx on'
    • Hit apply
    • (done)

If NumLock needs to be enabled because its off, just use % numlockx on.

  • This is what I need. Working on Xubuntu 16.04. – kodmanyagha Jul 8 '17 at 18:31

A rather hackish workaround is to add a cron job that runs the following command

setleds +num

every 30 seconds or so to turn NumLock on.

See also


It may not be the best solution, but this worked for me:

stdbuf -oL xinput test 11 | mawk -W interactive '$3==77 {printf "/usr/bin/numlockx on\n"}' | bash

Where 11 is the id of your keyboard. Do a xinput list to determine your keyboards id (in my case it's 11):

user@host:~$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ DualPoint Stick                           id=12   [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS DualPoint TouchPad          id=13   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Video Bus                                 id=6    [slave  keyboard (3)]
    ↳ Sony Vaio Keys                            id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ Power Button                              id=9    [slave  keyboard (3)]
    ↳ USB 2.0 Camera                            id=10   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]

Obviously, numlockx must be installed for that to work.


  • stdbuf -oL modifies buffering operations of the output stream to line buffered
  • xinput test 11 prints the pressed keys to stdout
  • mawk -W interactive '$3==77 {printf "/usr/bin/numlockx on\n"}' for every line that is printed and contains 77 (the numlock key), build a command /usr/bin/numlockx on ...
  • | bash ... and pipe it to bash to execute it.

You can insert this oneliner in one of the desktop environments initial scripts or run it in the background.


I also want the numeric keypad number keys to always be numbers, none of the KP_... stuff.

My solution is part of my Remapping Apple Keyboard for use with Linux repo.

Basically, it just remaps Num_Lock as F20, and the numbers as themselves.

This solution always provides the desired result and an extra function key as fringe benefit.


Create the following script and make it executable with chmod +x <filename>

if [ -x /usr/bin/numlockx ];then
/usr/bin/numlockx on

Put the file path in .config/openbox/autostart

Or place it as a cron job that checks every couple minutes and runs the script if numlocks is off.

crontab -e 
*/1 * * * * <path-to-file>

Or just run the script in a loop.

  while [ x -eq 0 ];do
    if [ -x /usr/bin/numlockx ];then
    /usr/bin/numlockx on

If you don't have numlockx you should be able to get it with sudo apt-get install numlockx

  • No, this is certainly not a good solution. Sorry – Martin Vegter Nov 8 '13 at 15:18
  • 1
    Can you explain why not? – Jeight Nov 8 '13 at 17:52
  • 1
    Well, because it is a very dirty workaround. It does not fix the underlying problem, it only sweeps the symptoms under the carpet. – Martin Vegter Nov 11 '13 at 13:01
  • Unfortunately, if xmodmap doesn't work, you don't really have any other options. Writing a script to check and enable numlock, isn't sweeping the problem under the rug. Think of it as a check-and-balance for fat fingering the key. There are no side effects and the script can easily be stopped/started at any time. It's really not that dirty of a workaround. I've seen much much worse done in the actual source code of programs that you use every day. – Jeight Nov 11 '13 at 18:52
  • how can you be so sure, I don't have other options? – Martin Vegter Jun 24 '14 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.