Keymapping problem when working with Emacs and Openbox

emacsopenboxxmodmap

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

Best Answer

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.

Related Question