Ubuntu – Remapping Caps Lock to Control and Escape (not the usual way)

keyboardxmodmap

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.

Best Answer

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.