Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to remap the CapsLock key system wide such that when the CapsLock button is pressed by itself it acts as the escape key and when pressed with another key it acts as the control key?

share|improve this question
4  
This seems like it would be very difficult. For example, it couldn't generate key down events, because you don't know which key was just pressed. If it's released without another key being pressed, then it was Escape, otherwise it was Control. –  cjm Feb 17 '12 at 17:12

3 Answers 3

up vote 11 down vote accepted

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.

share|improve this answer
    
I made a hacky script to do this: github.com/cmatheson/super-caps –  cam Apr 5 '13 at 5:13

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.

share|improve this answer

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 http://git.adirat.com/carpalx-keyboard

share|improve this answer
    
the link is dead, could you please update it? thanks! –  qed May 13 '13 at 15:31
    
I updated it, sorry for the delay –  gimmesudo Jun 12 '13 at 1:10
    
Bitbucket says "You do not have access to this repository." Can you make it public again? Thanks! –  Tianyi Cui Jul 5 '13 at 0:03
    
@TianyiCui check the link now –  gimmesudo Jul 5 '13 at 5:48

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.