Ubuntu – Using setxkbmap for a simple remap (similar to xmodmap)

14.04xkbxmodmap

I've faced some issues after remapping keyboard with xmodmap: settings get reset randomly after 2-20 minutes after applying. Googled it but no help: something resets them, but all mentions apply to xfce, while I'm under usual 14.04 Ubuntu with unity.

I saw phrases like 'use xkb, forget xmodmap', but still have no idea how to do that. It's either classified or very complicated, because amount of info on that is significantly smaller than for xmodmap way.

Here's my list of customisations:

xmodmap -e "keycode 84 = Down"
xmodmap -e "keycode 79 = Home"
xmodmap -e "keycode 80 = Up"
xmodmap -e "keycode 83 = Left"
xmodmap -e "keycode 85 = Right"
xmodmap -e "keycode 87 = End"
xmodmap -e "keycode 90 = Insert"
xmodmap -e "keycode 91 = Delete"
xmodmap -e "keycode 89 = Next"
xmodmap -e "keycode 81 = Prior"

where keycodes are corresponding keys on numpad, with numlock = off (basically, I'm replacing KP_Del with Delete, KP_Home with Home etc – don't ask why))

Can someone help to find a way to do that using xkb – at least one of the lines? And where to find the "names" of keys for other so I could do the rest by example?

Best Answer

You can follow the general idea seen in my answer on a similar problem; if you still want layout switching (although still quite broken) you should define a new layout or variant.

Notice that the template to copy and modify for the editing an keypad is a bit difficult to find. In my keyboard, for example, the geometry is "pc105"; this is defined in /usr/share/X11/xkb/symbols/pc. If you look into it, it include:

[...]
key <SPCE> {        [        space          ]       };

include "srvr_ctrl(fkey2vt)"
include "pc(editing)"
include "keypad(x11)"

key <BKSP> {        [ BackSpace, BackSpace  ]       };
[...]

The keypad is defined in the file /usr/share/X11/xkb/symbols/keypad

[...] 
default  partial hidden keypad_keys
xkb_symbols "x11" {
   include "keypad(operators)"

   key  <KP7> {        [  KP_Home,     KP_7    ]       };
   key  <KP8> {        [  KP_Up,       KP_8    ]       };
[...]

For the name of the key symbols (keysims), the best place to look is into the file /usr/include/X11/keysymdef.h; you may need to have the development packages installed to have it (or install it by instaling x11proto-core-dev):

[...]
/* Cursor control & motion */

#define XK_Home                          0xff50
#define XK_Left                          0xff51  /* Move left, left arrow */
#define XK_Up                            0xff52  /* Move up, up arrow */
[...]

the keysym name is the one you have once removed the "XK_" string.