Reassign Ctrl and Alt keys - xmodmap 'BadValue' error

Looking at the workaround linked by Giles, this is what worked for me:

clear Mod1
clear Mod4

keycode 204 = NoSymbol NoSymbol NoSymbol NoSymbol
keycode 206 = NoSymbol NoSymbol NoSymbol NoSymbol

keycode 64 = Control_L Control_L Control_L Control_L
keycode 133 = Alt_L Alt_L Alt_L Alt_L
keycode 134 = Alt_R Alt_R Alt_R Alt_R
keycode 108 = Control_R Control_R Control_R Control_R

add Control = Control_L Control_R
add Mod1 = Alt_L Alt_R

My Option keys now function like Control keys and my Windows Keys like Alt keys.


This has already been reported as Debian bug #564327, Debian bug #565279, Ubuntu bug #524774, and FreeDesktop bug 20145. There is a source patch attached to the FreeDesktop bug discussion. There are several workaround proposals in the Ubuntu bug discussion, in particular a .Xmodmap workaround.


The problem arises when you try to add a keysym to a modifier which is already added to another modifier key. It is vital to know, that if you add a keysym to a modifier all other keysyms that companion the keysym in case are added also as to that modifier.

For example:

clear mod5
add mod5    = ISO_Level3_Shift Mode_switch

can result in

mod5        backslash (0x33),  Caps_Lock (0x42),  ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

because you have something like

keycode  66 = Caps_Lock NoSymbol ISO_Level3_Shift

in your ~/.Xmodmap (View the current keycode to keysym mapping via xmodmap -pke)

which will produce the BadValue error in question when you also try to do something like

add lock    = Caps_Lock

because Caps_Lock is already added to the mod5 modifier.