NumPad Rebooted

13 Oct 2020

If you use the PageUp key a lot (e.g. accessing shell history) and instead of hitting PageUp you hit NumLock? and then it happens several times? the solution for me was to remap the NumLock key to become another PageUp.

This is for systems using Udev (which is now part of systemd), and a USB or PS/2 keyboard; I am not sure this is feasible for laptops, since as far as I know, on a laptop keyboard switching the Numpad on/off can be useful, gives you more keys on the already cramped keyboard.

I constructed that line from the vendor and product, respectively (we noted them down earlier). From /usr/lib/udev/hwdb.d/60-keyboard.hwdb:

    #  - Generic input devices match:
    #      evdev:input:bZZZZvYYYYpXXXXeWWWW-VVVV
    #    This matches on the kernel modalias of the input-device, mainly:
    #    ZZZZ is the bus-id (see /usr/include/linux/input.h BUS_*), YYYY, XXXX and
    #    WWWW are the 4-digit hex uppercase vendor, product and version ID and VVVV
    #    is an arbitrary length input-modalias describing the device capabilities.
    #    The vendor, product and version ID for a device node "eventX" is listed
    #    in /sys/class/input/eventX/device/id.

The parts we're interested in are YYYY and XXXX, i.e. the vendor and product; I set the rest of those hex digits to "*", since for example, it doesn't matter which bus-id is being used.

  • The second line:
      KEYBOARD_KEY_70053=pageup    # Remap NumLock to PageUp
    
    the part after # is a comment
  • Save the file, then as root, update the hwdb:
    systemd-hwdb update
    
  • To "apply" the changes, again as root:
    udevadm trigger /dev/input/eventX
    
  • replace X with the device number you used previously. If this doesn't work, remove/reinsert the usb cable/receiver from the machine.

    Now try the Numlock key, pressing it should be the same as pressing PageUp.

    To revert this change, simply remove the foo.hwdb file and:

    systemd-hwdb update
    udevadm trigger /dev/input/eventX
    
    if the last command above doesn't "apply" the changes remove/reinsert the usb cable/receiver from the machine.

    * * *

    Of course now you have no way to toggle the Numpad :), so the next logical step is to remap the number keys on the Numpad to always be in number mode i.e. 1 on the Numpad always types 1, 2 on the Numpad always types 2 ...etc, regardless of the state of NumLock. On my system I needed to use:

     KEYBOARD_KEY_70062=0
     KEYBOARD_KEY_70059=1
     KEYBOARD_KEY_7005a=2
     KEYBOARD_KEY_7005b=3
     KEYBOARD_KEY_7005c=4
     KEYBOARD_KEY_7005d=5
     KEYBOARD_KEY_7005e=6
     KEYBOARD_KEY_7005f=7
     KEYBOARD_KEY_70060=8
     KEYBOARD_KEY_70061=9
     KEYBOARD_KEY_70055=asterisk
     KEYBOARD_KEY_70063=dot
     KEYBOARD_KEY_70058=enter
     KEYBOARD_KEY_70056=minus
     KEYBOARD_KEY_70057=plus
     KEYBOARD_KEY_70054=slash
    
    you simply repeat the above steps for each key.

    One other issue that this fixes is booting and then trying to use the Numpad only to find NumLock isn't "on", this way it's always "on" :)

    I hope this mini-tutorial was useful.