Because of the layout of my keyboard, I want to have numlock permanently pressed and use the numlock key as a delete key. I can't seem to get this to work. Any ideas on how to do this would be appreciated.

Edit: I am running on Ubuntu 16

Here is what I have tried:

Use Xmodmap with numlockx

Inspired by this question. My understanding is that xmodmap is deprecated, so this is probably not a great idea.

  • Create a file ~/.Xmodmap with line keycode 77 = Delete NoSymbol
  • Run xmodmap ~/.Xmodmap
  • Run numlockx on

This allows numlock to work as delete and enables the num pad until the first time I press the numlock key. Then the numlock key disables the num pad.


  • Edit /usr/share/X11/xkb/symbols/us to have key <NMLK> { [Delete, Num_Lock] }; at the end of the basic keymap.
  • restart computer

also tried:

  • Edit /usr/share/X11/xkb/symbols/us to have replace key <NMLK> { [Delete, Num_Lock] }; at the end of the basic keymap.
  • restart computer

This suffers from similar problems as the other method, being able to delete works, but the numlock key turns off the numpad. It also seems to mess with other keys like the windows key when the num pad is enabled. I do like that I get control of the numlock using shift+numlock. I can't find any difference between using replace and not using it.


Here is a way to do this using only xkb, which I think is superior to using xmodmap. This answer includes more details on what I wanted to achieve than the original question did. Xmodmap and xkb don't always play well together, this approach allows a lot more flexibility:

This is all coming from: https://wiki.archlinux.org/index.php/X_keyboard_extension

There is a list of available keysyms that seem to work here: http://docs.ev3dev.org/projects/grx/en/ev3dev-stretch/c-api/input_keysyms.html

This is being done manually to allow you to start with the configuration that is already there on your computer to prevent compatibility issues with different keyboards. Examples of prior runs of this are seen in config_files/linux/keyboards

Begin by running xkbcomp $DISPLAY output.xkb to get your current keyboard settings. Then add:

    interpret osfLeft{
        repeat= True;
        action = RedirectKey(keycode=<LEFT>, clearmodifiers=Lock);
    interpret osfRight{
        repeat= True;
        action = RedirectKey(keycode=<RGHT>, clearmodifiers=Lock);
    interpret osfDown{
        repeat= True;
        action = RedirectKey(keycode=<DOWN>, clearmodifiers=Lock);
    interpret osfUp{
        repeat= True;
        action = RedirectKey(keycode=<UP>, clearmodifiers=Lock);
    interpret osfEndLine{
        repeat= True;
        action = RedirectKey(keycode=<END>, clearmodifiers=Lock);
    interpret osfBeginLine{
        repeat= True;
        action = RedirectKey(keycode=<HOME>, clearmodifiers=Lock);
    interpret osfEscape{
        action = RedirectKey(keycode=<ESC>, clearmodifiers=Lock);

to the compatibility section of the generated file.

To the bottom of the types section, add:

   type "CUST_CAPSLOCK" {
       modifiers= Shift+Lock;
       map[Shift] = Level2;            // Note that this maps Shift only of {Shift,Lock} to Level2. Alt+Shift will be mapped to Level2
       map[Shift+Lock] = Level3;       // but Lock+Shift won't map to Level2 even without this line.
       map[Lock] = Level3;
       level_name[Level1]= "Base";
       level_name[Level2]= "Shift";
       level_name[Level3]= "Lock";
   interpret osfDelete{
       action = RedirectKey(keycode=<DELE>, clearmodifiers=Lock);

Search for interpret Caps_Lock and change the LockMods to SetMods so that caps lock only sets the modifier, doesn't lock it.

To allow capslock + WASD to work as arrow keys: edit the keys <AD02>, <AC01>, <AC02>, <AC03> to have type CUST_CAPSLOCK and have respectively osfUp, osfLeft, osfDown, osfRight in the third position.

To allow capslock + HJKL to work as arrow keys: edit the keys <AC06>, <AC07>, <AC08>, <AC09> to have type CUST_CAPSLOCK and have respectively osfLeft, osfDown, osfUp, osfRight in the third position.

To allow capslock + 0 to register as home and capslock + $ to register as end: edit the keys <AE04> and <AE10> to have type CUST_CAPSLOCK and have respectively osfEndLine and osfBeginLine in the the third position.

To allow capslock + space bar to register as escape (handy for vim) edit the key <SPCE> to have type CUST_CAPSLOCK, have space in the second position and osfEscape in the third position.

To turn the numlock key into a delete key and make capslock + numlock make the <NMLK> have type CUST_CAPSLOCK, have position one and two have osfDelete and posiition three have Num_Lock

Now upload the changed file back into the server with: xkbcomp output.xkb $DISPLAY.

If everything works, put file somewhere, ~/.Xkeymap works and create a script for example named ~/start_keyboard.sh with:


xkbcomp ~/.Xkeymap $DISPLAY

Make it executable (chmod u+x ~/start_keyboard.sh) and add the script to your startup applications.


Please go through the 30sec Video https://imgur.com/3eLhv14

  1. Swap the keys Num_Lock & Delete with below code in ~/.xmodmaprc file. Create the file, if you have not yet assigned for xmodmap.

Change the keycodes based on your keyboard results in below code.

keycode 77 = Delete
keycode 119 = Num_Lock
clear Mod2
add Mod2 = Num_Lock
  1. Check swapping of keys working or not after running the command xmodmap ~/.xmodmaprc
  2. If swapping of keys worked, create a startup application for xmodmap like below.

enter image description here

at this point you have achieved almost what you want that is the physical key which appears as NUMLOCK working as DEL and the physical key DEL working as NUMLOCK.

  • To toggle Numlock State On and Off you would like to use Shift+Physical Key NUMLOCK as you mentioned in the Question, this can be achieved with xbindkeys in combination with xte or xdotool etc. for simulating the Num_Lock key which is Physically the DEL key at this stage.

Paste the below code in the file ~/.xbindkeysrc.scm & REBOOT. Create the file, if not yet created for xbindkeys. Change the value "c:77" based on the results from your keyboard. by running xbindkeys --key and pressing the physical key NUMLOCK

(xbindkey '(shift "c:77") "xte 'key Num_Lock'")

This means when you press Shift+NUMLOCK it simulates the DEL key and thus changing the Num_Lock state On and Off.

In the below GIF you can observe on the top left the symbols 1 and Shift, the symbol 1 toggles as I press Shift+NUMLOCK key press and release.

enter image description here

  • Thanks for the response. This seems to suffer from the same problem I mentioned above, where the numlock key works as delete as expected, but when the numpad is enabled, the nunlock key also disables the numpad. Your solution does however improve on what I had in that it does not disable the windows key. – Michael Sobrepera Apr 5 '19 at 21:19
  • No worries. Seems to work now. Thanks! – Michael Sobrepera Apr 8 '19 at 18:17

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.