Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to remap my right alt to behave like my right ctrl so I can use my right thumb to press the ctrl button. This is ubuntu 12.04.

I've created the file .Xmodmap in my home folder with the following content:

clear control
clear mod1
!keycode 64 = Alt_L Meta_L
keycode 108 = Alt_R Meta_R
add control = Control_L Control_R Alt_R
add mod1 = Alt_L Meta_L

As you might guess, my left alt key has keycode 64 and my left alt key has keycode 108.

This actually works in the sense that my right alt key behaves as if I press the ctrl key.

However my left alt key now doesn't do anything anymore, which means I don't have an alt key left. This is strange given that xmodmap gives the following output:

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69),  Alt_R (0x6c)
mod1        Alt_L (0x40),  Alt_L (0xcc),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

The strange thing is that when I remove the Alt_R mapping onto control the alt keys work

(ie., change the second to last line to:)

add control = Control_L Control_R

Now even my right alt behaves as an alt key which confuses me. After removing the Alt_R mapping from the control line the output of xmodmap gives:

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_L (0xcc),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

Hope you guys can help,

ps. I used this website as a source

share|improve this question
up vote 4 down vote accepted

You should be able to simply use Keyboard Layout >> Options >> Ctrl key position >> Right Alt as Right Ctrl, but this doesn't work. This has already been filed against Debian as Bug#663218

1) Start fresh by deleting ~/.Xmodmap.

2) Note that you do not need to clear Control and Mod1. This makes it easier to change only what you want. Your ~/.Xmodmap shoud be:

!Swap right control and right alt
remove Control = Control_R
remove Mod1 = Alt_R
keycode 105 = Alt_R
keycode 108 = Control_R
add Control = Control_R
add Mod1 = Alt_R
share|improve this answer
    
Thank you. This works flawlessly! – Hoogendijk Apr 12 '13 at 9:39

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.