Today on hacker news there was a clever article on custom shortcut keys.

The author talks about a technique for remapping a modifier key such as CTRL to ESC if CTRL were pressed without a modifier. This is useful in vim because of how often you need to press ESC.

Another technique he describes is mapping the open parenthesis, ( to the left shift key, and ) to the right shift key.

If another key is pressed when shift is held down, the shift key behaves normally.

The author describes the software he uses on OSX, but is there a way to do this on Windows?

I've heard of AutoHotKey but it seems to only fire macros when simple keys are pressed, rather than the conditional state switch that this would require.

  • AFAIK AHK should allow you to check if a key is pressed without any modifier, then perform different actions based on the results of the check. – Karan Oct 4 '12 at 0:20

AutoHotKey can do that. You can definitely keep track of the key states, but there's another trick. To remap Ctrl pressed alone to Esc but keep the other Ctrl-based shortcuts, just add this in your default script:

Ctrl & AppsKey::Return
Ctrl::Send {Esc}

This will work fine for you unless you use Ctrl+AppsKey (the key that pops up the contextual menu), but this is highly unlikely. If so just change AppsKey to any key that you never use with Ctrl.

The trick is to make Ctrl a prefix by using it in front of & at least once, and then make the release of the key produce the keystroke you want.

  • Great trick! Saved me a lot of time, thanks so much! – Plynx Dec 6 '12 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.