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?

  • How exactly are you loading your "evdev" file? This looks a bit like a custom kernel keyboard translation table (which has nothing to do with evdev), but a very incomplete one. And if you use X, you should use xmodmap instead.
    – dirkt
    Commented Mar 24, 2017 at 6:52
  • 1
    How do I load it? It is the normal evdev under /usr/share/X11/xkb/keycodes/. It s being loaded upon login. What I posted with just a snippet from the file. Commented Mar 24, 2017 at 16:37
  • You already have the built-in xkb option (ctrl:ralt_rctrl) to make RALT function like RCTL. Do you absolutely need it to work as LCTL ? If not, use the built-in option. Otherwise it should be trivial to define a new option in the ctrl file (it's the same code, just change Control_R to Control_L)... Commented Mar 24, 2017 at 22:27
  • @don_crissti for "what the h--- is this rabbithole" values of "trivial"
    – quixotic
    Commented Mar 24, 2017 at 22:40
  • @quixotic - it should be trivial for someone who knows where the builtin option is defined and who also knows how to define a custom option or for someone who doesn't know all those things but who is an inquisitive mind... ;) Commented Mar 24, 2017 at 22:51

2 Answers 2


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:

  • Why does **xmodmap -e "keycode 108 = Ctrl_R" ** does not work ? Commented Jan 22, 2018 at 11:40
  • @Talespin_Kit this answer is about the XKB system; you should post a separate question.
    – quixotic
    Commented Jan 22, 2018 at 19:06

The file /usr/share/X11/xkb/keycodes/evdev is not an "evdev file", it's one of the many source files for the X keyboard translation table (xkb). No, it's not loaded upon login. Instead it serves as a source file for the compiler xkbcomp, and the output of the compiled filed are loaded when the X server starts. The whole topic is a bit complex, so don't go about making changes randomly and expect stuff to work. Also, the usual way to make your own keyboard mapping is to write new files, and leave the old ones in place. See for example An Unreliable Guide to XKB Configuration for an introduction.

If you want to make your right alt key work as control key, a better way is to leave those files as they are, make an ~/.Xmodmap file with the following two lines

remove mod4 = Alt_R
add control = Alt_R

test that it works by looking at xmodmap -pk for the old state, then loading it with xmodmap ~/.Xmodmap, then do again an xmodmap -pk and make sure it looks right.

The result of this will be that the right alt key still shows up under its own keycode, but is treated as the control modifier so you can use it in combination with other keys.

Some display managers load ~/.Xmodmap by default on login, some of the new display managers have lost this feature and you'll have to configure them to do that.

  • 1
    xmodmap still works in many contexts. but it has been deprecated for a decade and won't be around in Wayland or other post-X11 contexts, so i advise avoiding it whenever possible.
    – quixotic
    Commented Mar 24, 2017 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .