This is on Ubuntu 10.04.
Manually swapping the Windows and Alt keys
- System -> Preferences -> Keyboard
- Layouts tab
- Click "Options..."
- Expand "Alt/Win key behavior"
- 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(",") + "]"' \
"$1"
}
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.)