1

I want to use my right Alt as another Control key to use with Emacs.

I tried following (with modifications) this tutorial: http://earthviaradio.wordpress.com/2012/02/06/swapping-the-left-alt-and-ctrl-keys-in-ubuntu-11-10/

So now I have this in my .Xmodmap file:

clear control
keycode 108 = Control_R
add control = Control_L Control_R

After I restart X.org, it doesn't seem to have an effect on how keys behave. Key 108 still functions as Alt. But when I explore it with xev, I can clearly see my changes. When I press the right Alt, I get this:

keycode 108 (keysym 0xffe4, Control_R)

It seems to "know" about my changes, but to not respect them.

2 Answers 2

3

If you are one of the unfortunate people like me that could not get xmodmap to switch right Alt with right Ctrl, then maybe this will help.

If you press right Alt and e and you get é then this solution is for you (needs improvement).

Run this in the terminal (check your keycodes with xev):

xmodmap -e "keycode 108 = Alt_R Meta_R Alt_R Meta_R"

then put this code in your .Xmodmap:

remove Control = Control_R
remove Mod1 = Alt_R
keycode 105 = Alt_R
keycode 108 = Control_R
add Control = Control_R
add Mod1 = Alt_R

This code sets your Alt_Gr key to Alt_R, and then it swaps Alt_r with Ctrl_R.

If you want this to remain after you logout, put the following commands in any of your startup shell files, for example ~/.profile:

if [ -f $HOME/.Xmodmap ]; then
  xmodmap -e "keycode 108 = Alt_R Meta_R Alt_R Meta_R"
  /usr/bin/xmodmap $HOME/.Xmodmap
fi

sources: question1 question2

2

OK, found the right answer here https://askubuntu.com/questions/237564/remap-right-alt-to-behave-as-right-ctrl

I'll post exactly what I have in my .Xmodmap now, as what I want is a bit different than the linked question. I don't want to unbind my right Ctrl, only to add another one (the right Alt).

remove Mod1 = Alt_R
keycode 108 = Control_R
add Control = Control_R

This is the minimal impact on the keyboard I can think of. What it does is only unbind Alt_R and bind Control_R to the same key. This should work on any linux, not only Ubuntu, as the linked question. I tested on Ubuntu, Fedora and OpenSUSE.

1
  • This no more works as of Ubuntu 16.04. One relatively easy solution is to modify /usr/share/X11/xkb/keycodes/evdev and change the key codes for RALT and RCTL: <RCTL> = 108; <RALT> = 105; This is probably not a "correct" solution as it changes system wide files which will probably get overwritten on package updates etc. Still haven't found a better one though.
    – loxs
    Mar 3, 2017 at 6:37

You must log in to answer this question.

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