6

In Arch Linux, I have Caps Lock function as an alternate Ctrl: In the console through a personal keymap, and in X through a "kbd" option in xorg.conf.

I've already researched a little about changing Caps Lock to a Hyper modifier, and it sounded like this wasn't feasible in the console, but is there any way I can do this for X?

Here's what I currently use for X:

Option "XkbOptions" "ctrl:nocaps"

Is there an XkbOptions option or something similar to make Caps Lock act like an additional modifier?

My goal in this is to be able to create more custom keymappings in Emacs with the new modifier.

2

While the other answers using xmodmap are correct, there is a far easier way. Instead of:

Option "XkbOptions" "ctrl:nocaps"

Just use:

Option "XkbOptions" "caps:hyper"

You can find all the options in /usr/share/X11/xkb/rules/base.lst

  • 4
    For me this assigned caps to super key, not hyper key. – Alex Moore-Niemi Mar 26 '17 at 3:55
8

This may be easier to do with xmodmap. Put the following into your .xsession or .xinitrc:

xmodmap -e "keysym Caps_Lock = Hyper_L"

You will also need to make sure Hyper_L is assigned to a modifier map not shared with other keys, otherwise it may generate the modifier for those keys instead (or those keys may become Hyper). Run xmodmap with not parameters (your output may differ):

> xmodmap
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock      
control     Control_L (0x25),  Control_L (0x42),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce), Hyper_L (0x4e)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

In this example, Hyper_L is assigned to the same modifer as the Super keys, and so is treated as a Super key. These commands will remove it from mod4 and put it into the empty mod3 modifier map:

xmodmap -e "remove Mod4 = Hyper_L" -e "add Mod3 = Hyper_L"

If Hyper_L doesn't appear in the modifier map listing, the remove command may not be necessary.

The modifier map arcanity is due to how X11 communicates whether a modifier is down. It sends a one-byte bitfield, each bit corresponding to one of the modifier maps, rather than sending "Hyper" or "Super". Applications have to go and look at the modifier map and figure out what a particular bit actually meant. If you have e.g. both Super and Hyper keys assigned to mod4, an application has no way to tell if Super or Hyper (or both) is being held down.

  • 1
    It works (xev picks up CapsLock as Hyper_L)...but its acting more like Shift than Ctrl/Alt, and Emacs doesn't pick it up as a modifier. Is there something additional I can do? – bitflips Sep 21 '13 at 20:10
  • 1
    @mellowmaroon I expanded my answer, it should now have what you need to get it working. I'm guessing an xmodmap -e "remove shift = Hyper_L" -e "add mod3 = Hyper_L" may be what it needs, or maybe mod1 or mod4 instead of shift. – wingedsubmariner Sep 21 '13 at 21:03
  • I tried moving Hyper into Mod3 like you have, but it's still doing the same thing. I really appreciate the assistance though. Anything else that might be messing it up? – bitflips Sep 21 '13 at 22:11
  • 1
    @mellowmaroon This answer should have everything you need. Maybe your initial modifier configuration is different from wingedsubmariner's and so you need to change it differently. Post the output of xmodmap. – Gilles 'SO- stop being evil' Sep 21 '13 at 23:06
  • Ok I have everything working now! It turned out to be the console Emacs' inability to detect Super and Hyper (at least with urxvt) that was throwing me off. Thanks so much! – bitflips Sep 22 '13 at 0:10
3

This worked for me:

keycode 66 = BackSpace
remove Mod4 = Hyper_L
add Mod3 = Hyper_L
keycode 66 = Hyper_L

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.