CMD & control keys swap in ubuntu

Phoenix picture Phoenix · Aug 17, 2011 · Viewed 11.1k times · Source

I have an Apple keyboard with a cmd key which I'm trying to swap with the control key.

From googleing the problem and searching across the forum I came with a several solutions. Unfortunately none of them worked for me. I've tried using the standard "Keyboard layout", Xmodmap & whatever I came across. The closest I got is swaping them but disabling the arrow keys.

I'm using ubuntu 11.

Hope someone can help me. Thank you in advance.

Edit:

This is my xmodmap result:

    shift       Shift_L (0x32),  Shift_R (0x3e)
    lock        Caps_Lock (0x42)
    control     Control_L (0x25),  Control_R (0x69)
    mod1        Alt_L (0x40),  Alt_R (0x6c),  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)

I want the control to be mod4 and vice versa. Thanks..

Answer

kalaracey picture kalaracey · Jun 27, 2012

EDIT: Just realized that this post was from six months ago. I doubt this will be any help, as you've probably (hopefully!) already gotten this solved, but, whatever.

Here's what you need to do:

Add the following to your ~/.Xmodmap file:

clear control
clear mod4

keycode 105 =
keycode 206 =

keycode 133 = Control_L NoSymbol Control_L
keycode 134 = Control_R NoSymbol Control_R
keycode 37 = Super_L NoSymbol Super_L

add control = Control_L
add control = Control_R
add mod4 = Super_L

To test this right now, just do xmodmap ~/.Xmodmap

Now, to have this happen every time at startup, add to the end of your (and/or create a new) ~/.xinitrc file the following:

xmodmap /home/your_username/.Xmodmap

Now restart / logout / restart X and you should be swell! Any trouble, please comment.