4

I have been trying to switch the Ctrl and CMD key on my MacBook for a while, but nothing seems to work.

A lot of the answers say to go to System Settings > Keyboard Layout and change it there, but I have a brand new installation of Ubuntu, and it does not have that feature.

I've also tried adjusting the xmodmap, which works for the current session, but when I reboot, the settings aren't saved.

To try to save it, I have added the command xmodmap ~/.Xmodmap to my Startup Applications, but that didn't work. I have also tried adding the command to the file /etc/profile.d/myfile.sh (I also altered the permissions). I have tried the file ~/.xinitrc file and many other ways, but nothing seems to work.

However, when I go to my shell and type in xmodmap ~/.Xmodmap, it works. So, I'm not sure what I'm doing wrong here.

Does anyone have any idea what I'm doing wrong?

2 Answers 2

2

The gnome-tweak-tool provides an option "Left Alt is swapped with Left Win". You may install gnome-tweak-tool with sudo apt install gnome-tweak-tool and the option can be found in the "Typing" menu.

0

To reload a configuration on login, first save it to the file:

xmodmap -pke > ~/.Xmodmap 

then edit the file created, such as:

keycode 37 = Control_L NoSymbol Control_L
keycode  133 = Super_L NoSymbol Super_L

or viceversa.

You can run xev and press the buttons to verify their keycode.

Finally, edit the file ~/.xsessionrc (or create it if it does not exist) with the following text, and change execution permission:

chmod a+x ~/.xsessionrc

Content of ~/.xsessionrc file:

#/bin/sh 
# 
# Executed by startx (run your window manager from here) 

# read ~/.Xmodmap if it exists
if [[ -f "${HOME}/.Xmodmap" ]]; then
    xmodmap "${HOME}/.Xmodmap"
fi
6
  • If followed these instructions exactly, and it still didn't work May 14, 2014 at 21:24
  • i have edited my answer replacing .xsession with .xsessionrc. Adding a command echo "test" > ${HOME}/test_file after xmodmap command, runs correctly, therefore the xmodmap command is executed. But I believe that the settings are subsequently overwritten.
    – girardengo
    May 14, 2014 at 22:28
  • Ok, so there's been a new development, and I'm not totally sure why this is happening, but when I wake my computer from sleep, it goes to the log in screen, and then goes black, and goes back to the log in screen, and when I enter my password and try to log in, it gets stuck just displaying the background. However, when I restart my computer it works fine. Also, there's an error file called .xsession-errors now that says this: May 14, 2014 at 22:54
  • Script for ibus started at run_im. Script for auto started at run_im. Script for default started at run_im. init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd main process ended, respawning May 14, 2014 at 22:55
  • init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd main process ended, respawning init: at-spi2-registryd respawning too fast, stopped May 14, 2014 at 22:55

You must log in to answer this question.

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