Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Mac keyboard where the Alt/Win (i.e. Option/Command) keys are inverted compared to a regular PC keyboard, and I'd like to swap them. I haven't had any luck with xmodmap so far. The standard configuration is as follows:

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)

Currently, the left/right alt keys are keycodes 64 and 108, while the left/right windows keys are 133 and 134.

I appreciate any help!

share|improve this question

migrated from stackoverflow.com May 2 '11 at 12:22

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

This is my Xmodmaprc:

! Exchange left Alt and left Win
remove mod1 = Alt_L
remove mod4 = Super_L
add mod1 = Super_L
add mod4 = Alt_L
! Exchange tilde and lesser/greater
keycode  94 = grave asciitilde dead_grave dead_tilde grave asciitilde
keycode  49 = less greater less greater bar brokenbar bar brokenbar
! Steve, your keyboard sucks

You'll have to modify your .xsession or .xinitrc to call xmodmap .Xmodmaprc

share|improve this answer
add comment

I achieved this in Ubuntu 13.04 by combining Christophe's answer (which helped me, but didn't work for the modifiers and I don't need grave and tilde to be dead keys), another answer about setxkbmap, playing with different options in settings-keyboard-layout-options (even looking at the source code) and inspecting the current configuration using the command setxkbmap -query (which you should also run, to check your specific keyboard model and layout codes as they might differ).

I have one script which I call when I switch to an Apple keyboard (the crucial option being altwin:swap_lalt_lwin to swap Alt and Super modifier keys):

# clear all options
setxkbmap -model "pc105" -layout "hr,us" -option ""  

# set the Apple keyboard
setxkbmap -rules "evdev" -model "pc105" -layout "hr,us" -option "terminate:ctrl_alt_bksp,lv3:rwin_switch,grp:shifts_toggle,caps:ctrl_modifier,altwin:swap_lalt_lwin"

# swap the grave-tilde with less-greater key
#  - variant without dead keys
xmodmap -e "keycode  94 = grave asciitilde"
xmodmap -e "keycode  49 = less greater less greater bar brokenbar bar brokenbar"

And another one which I call when I'm back on a normal keyboard:

# clear settings
setxkbmap -model "pc105" -layout "hr,us" -option ""

# pc keyobard
setxkbmap -rules "evdev" -model "pc105" -layout "hr,us" -option "terminate:ctrl_alt_bksp,lv3:rwin_switch,grp:shifts_toggle,caps:ctrl_modifier"

Note that I added the settings

terminate:ctrl_alt_bksp,lv3:rwin_switch,grp:shifts_toggle,caps:ctrl_modifier

to enable ctrl+alt+backspace Gnome session termination, level 3 key access using the right win key, layout shifting by pressing both shift keys and turned my Caps Lock into an additional Ctrl (respectively). You might want to exclude some or all of them.

You can use AutoKey to bind the call to some keyboard shortcut, or call it from your .profile or .bashrc if you use the Apple keyboard all the time.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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