keyboard x11 xmodmap xkb – Assign Another Modifier to Alt Key for X11

keyboardx11xkbxmodmap

Aim:

I would like to assign Alt to CapsLock-key, and Meta to Alt-key. But in such way, Alt-key would no longer be recognized as Alt, and CapsLock-key would no longer be recognized as CapsLock.

openSUSE 11.4

Previously:

openSUSE 11.1 — since I am the only user of my computer I "simply" edited the /usr/share/X11/xkb/keycodes/xfree86 file and it worked without problem. Keys were wired to their symbols at the lowest level.

Problems:

  1. xkb

    I created a variant of Polish layout (pl_ext) which (for test) consists of such entries:

    key <CAPS> { [ Alt_L ] };
    modifier_map Mod1 { Alt_L, Alt_R };
    

    However this does simply nothing, CapsLock-key in xev is recognized (symbol) as Alt_L, but when I press CapsLock-key it behaves like CapsLock (e.g. assuming you have File in menu, Alt+F should open this menu, it does not).

    Question: How to define a layout file to set CapsLock-key as Alt, and Alt-key as Meta?

    Edit: Half of success here! Now I have such entries:

    key <CAPS> { [ Alt_L ] };
    modifier_map Mod1 { <CAPS> }; // this is a difference
    

    and this works as desired. This does not:

    key <LALT> { [ Meta_L ] } ;
    key <RALT> { [ Meta_R ] } ;
    modifier_map Mod5 { <LALT>,<RALT> };
    

    Alt-keys are recognized as Meta by xev, but I still can open the menus with Alt+F, switch windows, and I shouldn't. And on the other hand I cannot enter any national character, and I should.

  2. xfree86

    But now this does not work, I guess other file table is read instead of xfree86.

    Question: How to find out which keycode table file is used by system (X/Gnome)?

    Edit: The best option for me — editing keycode tables — was solved by macias's answer!

  3. xmodmap

    Half of success here. This part works as desired:

    remove Lock = Caps_Lock
    keysym Caps_Lock = Alt_L

    Now, I have trully CapsLock-key which is mapped to Alt. But this:

    keysym Alt_L = Meta_L

    …does strange thing. xev shows that Alt-key is mapped to Meta, but when I press Alt+F (this should be mapped to Meta+F –> doing nothing) the File menu is opened. What's more, when I press Alt+Tab, I get window-switcher (I should not — Alt is Meta now).

    Question: How to "delete" old behavior for Alt-key?

    Edit: This part is solved by Gilles's answer.

Summary:

Answering any question would (hopefully) solve my problem, however I prefer using xkb entirely because I could then pack all the files for xkb and change layout in one place. Thank you in advance for any help!

Best Answer

(This answer is about xmodmap only. I'm sure it's possible to do this with XKB, I just don't know how.)

Modifiers and keysyms are assigned independently. But you get strange effects if you don't set them consistently. I think all you're missing is the add command to assign a modifier to Meta_L, though you may also need to clear and reassign the modifier keys. You may replace Mod1 and Mod2 by Mod3, Mod4 and Mod5: they are interchangeable, just make sure you don't use one for two different purposes.

clear Mod1
clear Mod2
remove Lock = Caps_Lock
keysym Caps_Lock = Alt_L
keysym Alt_L = Meta_L
add Mod1 = Alt_L Alt_R
add Mod2 = Meta_L Meta_R
Related Question