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 want to remap Control, so that:

  1. If it is pressed and released with no other key, it acts as Escape.
  2. If it is pressed & held together with another key, it acts as Control (no change in behavior in this case).

I'm aware of How do I remap certain keys?, so I suspect it may be done with xmodmap. But that answer does not explain how to map the modifier keys. I looked into the examples and grammar sections of the xmodmap manpage, but they do not explain that. The answer in Remapping Caps Lock to Control and Escape (not the usual way) mention that it is not possible to do that to CapsLock, since it is a Lock key, but I hope this may be possible to do it with Control which is a mod key. A solution with something different than xmodmap will also be accepted. (I'm running Xmonad in Ubuntu 12.04, so perhaps there is a way to set this up in xmonad.hs?)

EDIT: The closest I can get is:

xmodmap -e 'remove Control = Control_L'
xmodmap -e 'keysym Control_L = Escape'
xmodmap -e 'add Control = Escape'

With this I get Escape when I press the left Ctrl key alone, but to get, say, Ctrl+A I have to press the left Ctrl key twice: "Ctrl, Ctrl+A" (rather than just "Ctrl+A") - not sure why I need to press it twice.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The latest reply to Remapping Caps Lock to Control and Escape (not the usual way) says this utility will do what you want: https://github.com/alols/xcape

share|improve this answer

This can be done with xmodmap, but be aware that if you have set some things up with setxkbmap, the latter program will override and clear xmodmap settings.

However, to do exactly what you want with xmodmap, you can enter

xmodmap -e "keysym Control_L control = Escape Control_L" 

Now, if you look at xmodmap -pm, Escape has been added to the control modifier. This means that when left control is pressed, escape will instead be the result, but when control is pressed with another key (as in Ctrl+C), it will still give the same result as before.

Test it by entering in the terminal man xmodmap and then press ctrl while looking at the manpage and it will echo 'esc', but when you press Ctrl+Z it will suspend the page.

If you wish to reset your experimentations with xmodmap, logout and login again, and if you want to set the above xmodmap command as a startup item, see my answer here:

share|improve this answer
    
Thanks for your answer. Unfortunately, after I apply your steps I end up in almost the same situation as I mentioned above; that is, Ctrl+A, Ctrl+K, Ctrl+R etc. do not work (they send escape instead). To really get, say, Ctrl+A, I have to press the Ctrl twice, the second time together with A. (FWIW, I have never set setxkbmap, unless it comes with default ubuntu 12.04 install). –  psvm Nov 27 '12 at 3:01
    
@psvm It did work for me- I was able to use ctrl as escape and then ctrl + C, for example, so I'm not sure why it didn't for you. It is odd that you have to press ctrl twice: I think this could be part of the problem; it could be a damaged key. I should also check to see if you have applied any settings in the keyboard gui, as perhaps those settings are causing the problems. If it is a problem with your keys, then no commands will work successfully. –  user76204 Nov 27 '12 at 11:32
    
Let me be more clear: I agree with you that Ctrl+C, Ctrl+Z do work. I disagree that Ctrl+K, Ctrl+R, Ctrl+A work. That is, I claim that with this solution, some combinations work and some do not. Could you check for example that Ctrl+A work on the command line after applying your solution? Just open a simple terminal and type something at the bash prompt and then use Ctrl+A: do you get the cursor to the beginning of that line? For me it does not work (default installation of 12.04, never touched the keyboard settings) and I have to press A twice or Ctrl twice. –  psvm Nov 27 '12 at 17:47
    
@psvm I'll check that, just a minute. –  user76204 Nov 27 '12 at 17:48
    
@psvm Yes, you are correct- crtl-a does take two presses of ctrl, but ctrl-c and ctrl-z do work. I'll see if I can find out why. –  user76204 Nov 27 '12 at 17:50

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.