Remap CapsLock to Escape and Control System Wide

I have found a very good solution called xcape. From the README:

xcape runs as a daemon and intercepts the Control key. If the Control key is pressed and released on its own, it will generate an Escape key event.

This makes more sense if you have remapped your Caps Lock key to Control. Future versions of this program might do that mapping for you, but for now this is something that you have to do yourself.


I mapped Caps to Escape so that I would be more comfortable typing in Vim. I used xmodmap, and put this in ~/.Xmodmap.

clear Lock
keycode 0x42 = Escape

To apply: xmodmap ~/.Xmodmap. You can put this in a file such as ~/.bash_profile (I put in in ~/.xinitrc, because I don't use a login manager.

To map CapsLock + [another Key], consider using xbindkeys.


A Linux-only solution for remapping keys system-wide is to write a simple udev rule. It won't depend on X, will work on any terminal or app and is portable between any recent Linux installs by simply copying two files.

You need to write 2 files: one containing the udev rule which tells the kernel to remap the keys and one containing the actual mappings you need.

Using this method I've remapped my whole keyboard, maybe the code is useful as inspiration https://github.com/10ne1/carpalx-keyboard

Tags:

Keyboard