X11 – How to Disable Keyboard’s Numeric Keypad

keyboard-layoutx11

I want to disable all numpad keys; the ones located on the right side of my keyboard.

How can I do this? Of course, I would also like to know how to revert the action an re-enable the numeric keypad.

I have tried different things, such as remapping:

xmodmap -e "keycode # = """

But I get an error:

xmodmap commandline1: bad keycode value

What did I do wrong?

Best Answer

To disable them via XKB you could comment them out in your X keycodes file (the one that corresponds to your keyboard - linux uses /usr/share/X11/xkb/keycodes/evdev). Numpad key codes start with <KP... so you could use the following to prepend those lines with //kp_dsbl (// is the comment and kp_dsbl is some arbitrary string that you can use later to identify those lines if you want to revert changes):

sed -i '/^[[:blank:]]\{1,\}<KP/s|^|//kp_dsbl|' /usr/share/X11/xkb/keycodes/evdev

or

ed -s /usr/share/X11/xkb/keycodes/evdev <<\IN
g/^[[:blank:]]\{1,\}<KP/s|^|//kp_dsbl|
w
q
IN

To re-enable them:

sed -i 's|^//kp_dsbl||' /usr/share/X11/xkb/keycodes/evdev

or

ed -s /usr/share/X11/xkb/keycodes/evdev <<\IN
,s|^//kp_dsbl||
w
q
IN
Related Question