štvrtok, 11. marca 2010

Keys mapping

Not all the keys on my TV card remote work with XBMC. I needed to map some of them to achieve certain behavior, e.g. I needed to use the backspace key which was not mapped to the remote.

The solution is very simple. First run the "xev" program. This program prints out the content of X events, such as key presses. Then press a key on the remote and make sure you see this in the "xev"-s output, such as:

KeyPress event, serial 31, synthetic NO, window 0x400001,
root 0x157, subw 0x0, time 69418336, (567,307), root:(620,340),
state 0x0, keycode 182 (keysym 0x1008ff56, XF86Close), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False


This is the output for the "Back" key on my remote. There's another event for KeyRelease, which does not interest us at this point. The important information is the "keycode", which is 182 in my case.

Next we need to map the keycode 182 to the particular keyboard key, in my case it is the Backspace key. Since I am using gdm, I put the mapping to the /etc/gdm/PostLogin/Default file. The mapping is:

xmodmap -e "keycode 182 = BackSpace"


And that's it.

Update 20120124: Now that Ubuntu switched to lightdm, the key mapping can be made permanent by adding the xmodmap commands to separate shell script and add this shell script to /etc/lightdm/lightdm.conf under "greeter-setup-script".