I alternate between a Unicomp clicky keyboard by day, and the Apple bluetooth keyboard by night.

The Apple keyboard physically swaps the Alt and Windows keys. How do I counteract this?

Also, how can I streamline the process since I switch keyboards twice per day.


This is on Ubuntu 10.04.

Manually swapping the Windows and Alt keys

  1. System -> Preferences -> Keyboard
  2. Layouts tab
  3. Click "Options..."
  4. Expand "Alt/Win key behavior"
  5. Choose between:
    • Default (when using the PC keyboard)
    • "LeftAlt is swapped with Left Win" (when using the Apple keyboard)

Semi-automated swapping

I have added this to my .bashrc:

# Output the gconf settings for enabled or disabled keyboard swapping based on whether the argument is "apple"
setting_for_alt_key () {
  gconftool --get /desktop/gnome/peripherals/keyboard/kbd/options \
  | ruby -e 'set = {}; STDIN.gets.strip.gsub(/\]|\[/, "").split(",").each{|x| set[x]=1}; set["altwin\taltwin:swap_lalt_lwin"]=1; STDOUT.write "[" + set.keys.select{|x| ARGV[0] == "apple" || x !~ /swap_lalt/ }.join(",") + "]"' \

kmac () { gconftool --set --type=list --list-type=string /desktop/gnome/peripherals/keyboard/kbd/options "$(setting_for_alt_key apple)"; }
kpc  () { gconftool --set --type=list --list-type=string /desktop/gnome/peripherals/keyboard/kbd/options "$(setting_for_alt_key)"; }

Then when I activate the Apple keyboard, I type kmac at the terminal. When I deactivate it, I type kpc. So far I have not been able to justify auto-detection.

(Also, if somebody has a better way to work with Gconf, either with gconftool-2 or perhaps language bindings, I'd love to hear it.)


Go to System>Preferences>Keyboard and add the appropriate keyboard layouts you want to use. Then in the layouts tab click the "Options..." button and find "Keys to change layout" and find a keyboard short cut that you will like.

  • To my knowledge, the keyboard layout is unrelated to my question of swapping the keys. Would you please confirm your technique and follow up? Thanks. – jhs Aug 16 '10 at 14:32
  • There are layouts for mac keyboards, and I cant really confirm since I haven't got a mac keyboard. – LassePoulsen Aug 16 '10 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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