Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an Apple keyboard and I had to do some remapping of the keys to make the mod-4 key the first key to the left of the Space bar for when working with Emacs. The below script worked fine when I was using the dwm window manager, but after switching to Openbox I have found that instead of swapping keycodes between the option and command keys, both of the keys are doing the same thing.

One odd thing I noticed, was on the new setup when I click run showkey and press the option and command keys I get 56 and 125 respectively, but these keys don't work at all when inserting them into the below script instead of the 64 and 133.

I must admit I created the script below by continually tweaking it until it worked so there could be a much better way of doing it.

.xmodmap

# switch alt and command...the switch is not being done properly
xmodmap -e "keycode 64 = Alt_L"
xmodmap -e "keycode 133 = Meta_L"

# remap of mod 4
xmodmap -e "clear Mod4"
xmodmap -e "add Mod4 = Super_L"

Update

I got used to the previous keyboard setup and gave up trying to tweak it. Unfortunately, after a recent restart the CapsLock to Ctrl no longer worked so here I am again.

This time instead of the mapping used above I ran xmodmap -pke > ~/.xmod and tweaked the keys there instead (which is much easier).

However, things are still not quite right. The CapsLock still functions as normal except when the xev command is run, then it returns the following which does seem to show the correct mapping:

# caplock
KeyRelease event, serial 40, synthetic NO, window 0x2200001,
root 0x156, subw 0x0, time 4858000, (57,-31), root:(426,402),
state 0x2, keycode 66 (keysym 0xffe3, Control_L), same_screen YES,
XKeysymToKeycode returns keycode: 37
XLookupString gives 0 bytes: 
XFilterEvent returns: False

# ctrl-L
KeyRelease event, serial 40, synthetic NO, window 0x2200001,
root 0x156, subw 0x0, time 4805947, (686,148), root:(1055,581),
state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False

# Alt-L
KeyPress event, serial 40, synthetic NO, window 0x2200001,
root 0x156, subw 0x0, time 4555825, (-158,-649), root:(959,133),
state 0x0, keycode 64 (keysym 0xffeb, Super_L), same_screen YES,
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False

# Super-L
KeyRelease event, serial 40, synthetic NO, window 0x2200001,
root 0x156, subw 0x0, time 4920564, (-63,169), root:(306,602),
state 0x40, keycode 133 (keysym 0xffe9, Alt_L), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False
share|improve this question
4  
On PCs (I don't know if this is also true on Macs) showkey doesn't show the same keycodes that X uses. Run xev to see the X keycodes and their actions. Show us the output of xmodmap -pm and the output of xev when you press each of the keys involved. –  Gilles Feb 22 '11 at 21:05
    
I added an update above for the xmodmap -pm command –  chris Apr 6 '11 at 6:30
    
You may want to take a look at wiki.archlinux.org/index.php/Apple_Keyboard and help.ubuntu.com/community/AppleKeyboard. To summarize, you can tell the keyboard driver in the kernel to behave differently, rather than hacking things in X. –  wingedsubmariner Sep 10 '13 at 12:50
    
If it was working in DWM my guess is that a conflict with ~/.config/openbox/rc.xml is the issue. –  MajorBriggs Dec 10 at 10:00

1 Answer 1

You probably need to place the following at the beginning of your ~/.xmod

remove Lock = Caps_Lock
remove Control = Control_L
remove Mod1 = Alt_L Meta_L
remove Mod4 = Super_L Hyper_L

And the following at the bottom of ~/.xmod

add Control = Control_L
add Mod1 = Alt_L Meta_L
add Mod4 = Super_L Hyper_L

This will update the system to recognize the modifier nature of these keys.

share|improve this answer

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.