Monday, November 2, 2009

Keypad/Numpad gone mad in KDE4

I upgraded to KDE4 – Kubuntu Karmic Koala (9.10).

All was fine, excepting for the numerical keypad. My notebook's design includes this keypad which allows me to use the digits (when NumLock is on) and the other keys, respectively (Del, Home, End, Page Up, Page Down, Ins) – when the NumLock LED is off.

I found it impossible to get this basic behavior out-of-the-box: I tried for several hours messing up with System Settings > Regional and Language > Keyboard Layout > Advanced > all kinds of XkbOptions.

Nothing seemed to work.

So I finally decided to "remap" these keys as if they were the independent ones (Delete, Home, End, Page Up, Page Down, Insert) from a default keyboard.

"xev" is a useful tool. For instance, pressing the "Home" key on the numpad when NumLock is off will make xev return the following information:
KeyPress event, serial 34, synthetic NO, window 0x5200001,
root 0x116, subw 0x0, time 49770457, (162,-8), root:(166,17),
state 0x0, keycode 79 (keysym 0xff95, KP_Home), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
Notice that all the keys that were troublesome (that wouldn't "do" anything) were the KP_something ones in this particular case.

My solution was to edit a .Xmodmap file where I re-mapped the keys I was interested in. I then included this file in Xsession's routines:
$ vim ~/.Xmodmap

keycode 79 = Home KP_7 Home KP_7 Home KP_7
keycode 87 = End KP_1 End KP_1 End KP_1
keycode 81 = Prior KP_9 Prior KP_9 Prior KP_9
keycode 89 = Next KP_3 Next KP_3 Next KP_3
keycode 91 = Delete KP_Decimal Delete KP_Decimal
keycode 90 = Insert KP_0 Insert KP_0 Insert KP_0
To quickly check if you achieved the results you were aiming for, run:
xmodmap ~/.Xmodmap
To make the changes permanent (i.e. have them loaded at each login), edit /etc/kde4/kdm/Xsession:
case $SHELL in
[... leave this unchanged ... ]
esac
if [ -f $HOME/.Xmodmap ] ; then
/usr/bin/xmodmap $HOME/.Xmodmap
fi
# invoke global X session script
. /etc/X11/Xsession
Just add the above text (the one in bold) in your /etc/kde4/kdm/Xsession file.

Logout and login again.

0 comments:

Post a Comment