Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to disable Capslock and make the following remaps:

Ctrl+Capslock => Capslock
Alt+Capslock => Escape (since my Escape key is broken)

Right now I'm trying to use Xmodmap.

I have only the following:

keycode 66 = NoSymbol Caps_Lock

This disables Capslock and maps Shift+Capslock to Capslock, but what I want is Ctrl+Capslock instead of Shift+Capslock.

I have no idea how to map Alt+Capslock to the Escape key.

I want to clarify that I don't need an answer to use Xmodmap, any method will be fine.

share|improve this question
1  
+1 All my life being frustrated how easy it is to press accidentally CAPS while typing fast only to a sentence later discover that you have to retype everything anew. –  Vorac Jul 12 '12 at 15:16
    
Its worse for me, I use vim. Oh the horror! <=O –  qtwtetrt Jul 22 '12 at 8:55

1 Answer 1

up vote 1 down vote accepted

Xmodmap cannot do what you're asking for, but it can bring you close.

The basic syntax for modifying the behavior of a key is

xmodmap -e "keycode  KEYCODE = KEYSYMBOL1 KEYSYMBOL1 KEYSYMBOL3 KEYSYMBOL4"
xmodmap -e "keysym KEYSYMBOL = KEYSYMBOL1 KEYSYMBOL1 KEYSYMBOL3 KEYSYMBOL4"

where

  • KEYSYMBOL2 gets triggered when pressing the key while pressing Shift.
  • KEYSYMBOL3 gets triggered when pressing the key while pressing ModeSwitch.
  • KEYSYMBOL4 gets triggered when pressing the key while pressing Shift + ModeSwitch.
  • KEYSYMBOL1 gets triggered when pressing the key with none of the above.
  • ModeSwitch is AltGr by default (only works on some keyboard layouts).

We can't set Ctrl or Alt to be the ModeSwitch key, since no key can serve as two different modifiers.

However, we can turn CapsLock into the ModeSwitch key:

xmodmap -e "keysym Caps_Lock = Mode_switch Mode_switch"

To remap CapsLock + Ctrl to the CapsLock key, execute the following commands.

xmodmap -e "keysym Control_L = Control_L Control_L Caps_Lock"
xmodmap -e "keysym Control_R = Control_R Control_R Caps_Lock"

Note the CapsLock is the modifier key here, so you have to press this key first.

We can't remap CapsLock + Alt or CapsLock + Super to Escape in the same manner, since Alt and Super serve different functions when pressed alone and when used as modifier keys.

Every other key will work fine. Examples:

  • For CapsLock + ` (standard US layout), use

    xmodmap -e "keysym grave = grave asciitilde Escape"
    
  • For CapsLock + Space, use

    xmodmap -e "keysym space = KP_Space KP_Space Escape"
    

Tips:

  • To make the remappings permanent, create/edit the file .gnomerc in your home folder and save the corresponding commands in it.

  • To undo all remappings, simply execute

    setxkbmap
    
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.