Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know how to use xmodmap to remap the Caps lock key so it acts as a Control key, or as an Escape key. I would like to combine both features as follows:

When I push, then release, the Caps lock key, it sends Escape. When I hold down Caps lock and push another key (say A), it send Control-A.

Is there some combination of xkb, xmodmap and something else that could make Caps lock behave this way in X?

I'm using Ubuntu Precise on a Macbook Air 3,1.

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

You can do the first (mapping Caps Lock to Esc) but you cannot do the second.

Simple Explanation: Caps Lock is just not designed to do something when pressed.

Elaborate Explanation: There are many types of keys. Two of them are Modifier Keys and Lock Keys.

Caps Lock is a Lock Key while keys such as Ctrl, Alt, and Shift are Modifier Keys.

It's apparent from their names that Modifier Keys modify the function of the next key(s) pressed, and Lock Keys act as a toggle switch to turn on or off some particular function.

Now, since Caps Lock is a Lock Key, you cannot have it behave like a Modifier Key without mapping it to one. Caps Lock by itself cannot function as a Modifier Key.

share|improve this answer
    
Thank you for confirming that X is not designed to do what I want. If an X guru wants to hack something to make it work, please get in touch with me. –  user372737 Aug 25 '12 at 23:52
    
As the unaccepted answer below, you certainly can do the second part with numerous utilities such as xcape or At-Home-Modifier. –  Sparhawk Aug 1 '13 at 11:48
add comment

I'm looking for this too. As of a week ago I found my self a partial solution using xmodmap:

add Control = Caps_Lock
remove Lock = Caps_Lock
keysym Caps_Lock = Escape

This is of course not working perfectly, it effectively send both Escape and Ctrl at the same time when I press CapsLock, but I was happy with it for a while.

Finally I found this little utility https://github.com/alols/xcape. So now I can simply remap CapsLock to Ctrl and let xcape do its job.

share|improve this answer
    
Another option is At-Home-Modifier. It's not in active development, and differs slightly from xcape by installing at root. However, it triggers through xorg.conf, and hence can act only on specific keyboards, while using other keyboards simultaneously. –  Sparhawk Aug 1 '13 at 23:13
add comment

I have this setup on my Mac and I had tried to find a way for Ubuntu without luck.

Well, it's now working. Thanks tungd for ponting me to xcape. What I have done is really simple and straightforward.

  1. Under System Preferences > Keyboard Layout > Options... > Ctrl key position, I checked 'Caps Lock as Ctrl'.

  2. xcape -e 'Control_L=Escape'

Done, Caps Lock works as Ctrl when used like a modifier, and as Esc when pressed alone (there's a slight delay of a few hundred milliseconds, as noted on the xcape README file, so it's still not as optimal as the Mac solution which uses KeyRemap4MacBook.)

share|improve this answer
add comment

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.