Map right alt to left control

keyboard shortcutsxkb

I would like to have my right alt key work as left control while still having left control work as left control. So I edited my evdev file like this:

<LALT> = 64;
<LCTL> = 37; // original binding 37
<SPCE> = 65;
<RCTL> = 105;
<RALT> = 37; // original binding: 108

However this does not work, now neither key is working as ctrl. How can I make this work?

Best Answer

The keycodes file you've changed is an XKB mapping that defines the symbol codes used in XKB layouts (<FOO>) by the keycodes emitted by the kernel keyboard driver when a key is pressed. Changing the codes there doesn't change what code the key generates, it changes what code the XKB layout thinks its dealing with when it sees the altered symbol.

Assuming you can get your system XKB files back to their original state, the XKB way to do what you want is to load an option that will override the standard layout. There's an existing option (ctrl:ralt_rctrl) that's close to what you want:

  # definition in /usr/share/X11/xkb/rules/evdev
  ctrl:rctrl_ralt       =       +ctrl(rctrl_ralt)
  # similar rule for swapped option?
  ctrl:ralt_rctrl       =       +ctrl(ralt_rctrl)

You can load that with setxkbmap:

$ setxkbmap -option ctrl:ralt_rctrl

If that does what you want, you can make it permanent by adding that command to a .xprofile or .xinitrc or your window manager's autorun script. In GNOME you may need other steps.

If you still prefer to have Alt_R remapped as Ctrl_L instead of Ctrl_R, you'd want to create a local override clause. Use the existing option as a starting point; it's in /usr/share/X11/xkb/symbols/ctrl. See my superuser answer on XKB modifications and some additional resources:

Related Question