Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Although there are lots of different articles how to change the left Alt to simulate win , I want to map the right Alt to do so. I want to move to 11.10, I fall back to unity 2d and dont have a win key. I kennot even get the keycode in the articles I found... Any help or good suggestions?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

You can use xmodmap to remap any key on the keyboard; in particular, you can remap the right Alt to act as a Super/Win key.

Create a file named .Xmodmap in your home directory with the following content:

! free up right-Alt for remapping
remove mod1 = Alt_R

! Right-Alt remapped to Super
clear mod4
keycode 108 = Super_R
add mod4 = Super_R

When you log out and then log in again, GNOME should ask you if you want to load the .Xmodmap file; answer "yes" and you're ready to go. (You will only asked once.)

Alternatively, you can load the .Xmodmap configuration from a terminal at any time:

xmodmap .Xmodmap

There are a few things that can vary depending on the X server version and keyboard model. The following items could help you adapt the .Xmodmap file to your specific environment.

  1. Check that your right Alt key is initially on mod1: Issue the command xmodmap in a terminal window, and you should get an output like this one:

    xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):
    
    shift       Shift_L (0x32),  Shift_R (0x3e)
    lock        Caps_Lock (0x9),  Caps_Lock (0x4e)
    control     Control_L (0x25),  Control_R (0x69)
    mod1        Alt_L (0x40),  Alt_R (0x6c),  Alt_L (0xcc)
    mod2      
    mod3        Mode_switch (0xcb)
    mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce)
    mod5      
    

    If the Alt_R tag does not appear in the mod1 line but on a different one, adjust your .Xmodmap accordingly.

  2. Check that your right Alt key is keycode 108: in a terminal window, type the command xev, then focus the small square window that popped up. If you type the right Alt key there, you should see lines appearing in the terminal window. Look for a stanza like this one:

    KeyPress event, serial 25, synthetic NO, window 0x5000001,
        root 0xbd, subw 0x5000002, time 867397196, (53,48), root:(54,49),
        state 0x0, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
        XLookupString gives 0 bytes: 
        XmbLookupString gives 0 bytes: 
        XFilterEvent returns: False
    

    The number after the keycode word is the one you want in your .Xmodmap file for remapping right Alt.

share|improve this answer
    
Thank you. I can keep my left all for all the things I need. –  deckoff Oct 23 '11 at 18:44
    
strange, although the solution used to work, now it stopped??? When I restart the PC and recreate the solution, it works until the next restart... –  deckoff Oct 25 '11 at 19:04
1  
@deckoff It means that your .Xmodmap file is not being read at the start of the X session. Try adding xmodmap ~/.Xmodmap to your .gnomerc (or equivalent) file. –  Riccardo Murri Oct 25 '11 at 19:21
    
I will try it. It seems it does not work when password login is disabled. If I see a login screen( no matter if I log out and I am logging in, or if I have enabled password login at start it will work).Please look here if you are willing to help. It seems the file is loaded, but not executed properly. –  deckoff Oct 26 '11 at 18:24
1  
Yes, adding xmodmap ~/.Xmodmap to .gnomerc worked –  deckoff Oct 26 '11 at 20:46

I found that simply:

remove mod1 = Alt_R
add mod4 = Alt_R

works as hoped. Am I missing any "gotchas" with this method?

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.