2
votes

I'm trying to remap three keys, left alt, right win and menu, to specific keys for emacs. Specifically, I wants to use RWIN as Hyper, my left alt as Meta and My MENU as Alt.

I setup xkb in this way. there are two files, the first one is super_hyper (in ~/.xkb/symbols):

partial modifier_keys
xkb_symbols "standard" {
    key <LALT> { [ Meta_L, Meta_L ] };
    replace key <RWIN>  { [ Hyper_R, Hyper_R ] };
    replace key <MENU>  { [ Alt_R, Alt_R ] };
    modifier_map Mod1 { <META>, Meta_L };
    modifier_map Mod3 { <HYPR>, Hyper_R };
    modifier_map none { <ALT>, Alt_R };
};

the second file (~/.xkb/keymap/mykbd) is really simple:

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"      };
    xkb_compat    { include "complete"      };
    xkb_symbols   { include "pc+it+inet(evdev)+compose(paus)+terminate(ctrl_alt_bksp)+super_hyper(standard)"};
    xkb_geometry  { include "pc(pc105)"     };
};

Then I setup all with

xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykbd $DISPLAY

xev shows that all works perfectly. And emacs works well with the hyper (right windows key) and meta (left alt key) modifiers. But when I use the menu key it responds like a meta modifier, like the alt key. How can I solve?

1
I am not sure but maybe this link can give you more insight : ergoemacs.org/emacs/emacs_hyper_super_keys.htmlhomeless
Thank you, but that link doesn't give any way to configure the keyboard other than the gnome/ubuntu GUI (that I suspect will give the xkb options configuration, that are very far to give me what I want). And I don't need a way to remap normal keys, I already can do that, I can have super and hyper easily. What I really need is to have an Alt key that is recognized by emacs as an Alt key.Totoro

1 Answers

3
votes

Your left alt key should already be mapped as a meta key. I will show you on an example how to configure Emacs to recognize the AltGr (right alt) as a hyper key. You can adapt the example then to your needs.

  1. Find out the key code of the AltGr key:

Run in a console: xev. Hit afterwards repeatedly the AltGr key and close then the program. In the output, you can read the key code for AltGr. I get:

...keycode 108 (keysym 0xffea, Alt_R)...
  1. Next, we check how our keys are bound with the following command: xmodmap -pm. In my case, I get:
shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3
mod4
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

In hexadecimal, the keycode 108 (hex 0x6c) is associated with Alt_R.

  1. Remove Alt_R from mod1 as we want to map it to hyper. This step is optional. For example, my menu key (hex code: 0x87) does not appear in this output. Therefore I can skip this step.
# remove all keys associated to mod1
xmodmap -e "clear mod1"
# but as we are only interested in Alt_R, re-assign those we removed wrongly
xmodmap -e "add mod1 = Alt_L Meta_L"
  1. Now, we can re-assign AltGr key to Hyper (you can choose other keys such as: Alt_R or Super_L, Super_H, ...:
xmodmap -e "keycode 108 = Hyper_R"
  1. Finally, the next step consists in assigning this key symbol to a modifier. I chose mod3 (mainly because it is empty):
xmodmap -e "add mod3 = Hyper_R"
  1. In Emacs, when I hit now AltGr-f, it tells me that H-f is undefined. I can go now and use the hyper key for new keybindings:
(global-set-key (kbd "H-f") 'find-file)

If I had chosen in step 4-5 to assign AltGr and mod3 to Super_R, I would have used "S-f" for the new keybinding in step 6. Similarly, assigning AltGr to Alt_R in step 4-5 would have resulted in using e.g. "A-f" when setting the binding.

EDIT

If you want to assign a key (e.g. menu key) to Alt_R, one has to make sure that the Meta_L key is mapped (e.g. to mod1). If Meta_L (e.g. assigned to Alt_L) does not appear in your xmodmap -pm output, then very likely, your key (e.g. menu) acts as a further meta modifier.