Ubuntu – Xmodmap remapping modifiers not working

14.04keyboardxmodmap

I am using a new keyboard, and trying to set it up to mimic the keyboard on my laptop. I'm using xmodmap on Ubuntu 14.04, and can't get it to work. I cleared the modifier keys like so :

xmodmap -e "clear mod1"
xmodmap -e "clear mod4"
xmodmap -e "clear Control"

And that works fine, afterwards the modifiers don't do anything. After that, I try to assign the Alt_R key to act as a super key, like so :

xmodmap -e "add mod1 = Alt_R"

However, the alt button then goes back to behaving like an alt button, instead of behaving like super and bringing up the Unity search when it's tapped. Is there a trick to getting the modifiers working with xmodmap?

Additionally, even after clearing control, with "xmodmap -e "clear Control", I can still use ctrl.

The keyboard I'm using is the das keyboard s ultimate, if that matters at all.

EDIT: A realization I made while messing around with xev and trying to solve the problem : When I run something like "xmodmap -e "keycode 133 = Alt_L" (keycode 133 is usually super), and then launch xev, when I look at the output it shows this :

KeyRelease event, serial 37, synthetic NO, window 0x2000001,
root 0x9e, subw 0x0, time 179020, (-382,66), root:(406,118),
state 0x40, keycode 133 (keysym 0xffe9, Alt_L), same_screen YES,
XKeysymToKeycode returns keycode: 64
XLookupString gives 0 bytes: 
XFilterEvent returns: False

As you can see, it sees the key press as Alt_L. However, the key is still behaving like a super key, activating the Unity search when pressed.

Best Answer

I'm not an expert myself, but I'll give it a try. First of all, let us make an xmodmap script at ~/.Xmodmap. I understand you want the right alt to function as a super key. I suggest this:

clear mod1
clear mod4

!Make right alt to look like Super_R
!I'm assuming your right alt has keycode 108, you can check using xev
keycode 108 = Super_R NoSymbol Super_R

!Add the Super_L and Super_R keys to the modifier mod4
add mod4 = Super_L Super_R

Your other alt key and super keys may now be messed up, but you can assign them to anything you want analogously. (If you don't want to change them at all, use xev to see what they did originally and assign them to that.) Just put all clears together first, then the assignings of keycodes to key names, then finally the assignings of key names to modifiers, and I think it should work. Normally, ~/.Xmodmap should be executed automatically on login, but if not, you can try adding a line

xmodmap ~/.Xmodmap

or

sleep 4 && xmodmap ~/.Xmodmap &

to ~/.bash_profile.