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.

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!

share|improve this question
    
If you've found an answer, please post it as such, and give enough information for other people who might be interested. (It's perfectly fine to answer your own question if you found the answer elsewhere or by yourself; you can even mark your answer as accepted if you like.) –  Gilles Mar 22 '11 at 22:22
    
@Gilles, ok, but I keep your answer as the answer, just to prevent possible accusation I did it for points. Besides, you help was very valuable for me. –  greenoldman Mar 23 '11 at 6:25
    
You don't get points for accepting your own answer anyway. (You do get points for the votes on your own answer, which is fair since you did the work.) The most important thing is to have the information clearly presented. There are now two answers to this question, one with xmodmap and one with xkb, and the page would read clearer if they were both posted as answers. –  Gilles Mar 23 '11 at 8:00

3 Answers 3

up vote 5 down vote accepted

(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
share|improve this answer
    
Big thanks. So indeed, I used Mod5 instead of Mod2 for Meta, and I can now write as expected (I use meta+key for many national characters). But oddly, now I have problem with CapsLock-key again -- it is binded to... Meta. I guess why, because once there is binding to Alt, but then Alt is redefined. So how to make a difference and once insist on code, and second time on symbol? I would like not to use raw keycodes because they could change from keyboard to keyboard. I cannot swap the order of keysyms, because in the last line I would get error. –  greenoldman Mar 19 '11 at 11:42
    
The problem with keysym Caps_Lock = Alt_L is that if you run it twice, it puts the system back into an undesired state. That's why I use keycodes; they vary between operating systems and architectures (not between keyboards), but not that often. –  Gilles Mar 19 '11 at 11:47
    
Thank you for explanation, I guessed right then :-). If you don't mind I will keep it a bit longer as an unanswered question, maybe somebody could solve my problem at xkb level, which would be more flexible (switching layouts kills xmodmaps). –  greenoldman Mar 19 '11 at 12:20

try this:

    key <CAPS>  { [ Alt_L, Alt_L ] };
    key <LALT> { [ Meta_L, Meta_L ] };
    modifier_map Mod1 { Alt_L, Alt_R };
    modifier_map Mod5 { Meta_L, Meta_R };

note the two level definitions. That is because the default for LALT is [ Alt_L, Meta_L ]; if you don't redefine the second one, it will remain Meta_L.

Look at this answer on xkb for how to redefine some keys without need to edit main default files (thus, no need to be root). In such case, you will need in the local symbols file a small section as:

partial modifier_keys
xkb_symbols "capsasalt_altasmeta" {
        replace key <CAPS>  { [ Alt_L, Alt_L ] };
        replace key <LALT> { [ Meta_L, Meta_L ] };
        modifier_map Mod1 { Alt_L, Alt_R };
        modifier_map Mod5 { Meta_L, Meta_R };
};
share|improve this answer

Editing keycodes approach

I found the answer on Polish Ubuntu forum. Now one does not edit "xfree86" file but "evdev" file. This way you can make permanent changes which work for all layouts.

Example (on Gilles request) -- log in as root, go to

/usr/share/X11/xkb/keycodes

make a backup of "evdev" file, and then edit it. Change the codes to your liking, for example in my case:

<LALT> = 66; // when I press CapsLock (66 code) system will report pressing LeftAlt
<LMTA> = 64; // I will get LeftMeta when pressing LeftAlt (64 code)

You can find what the codes by executing command "xev", but you can simply look at original "evdev" file.

Log out, log in, enjoy your new keyboard :-).

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.