Remap Caps Lock in Windows (escape *and* control)

8

6

There's plenty of utilities that remap keys, but I can't seem to find a very specific feature: I want to have caps lock act as the control modifier key when held down, but as escape when pressed on its own.

A similar question was posed here, and one of the answers provided an AutoHotkey script, however it is susceptible to the timing of key presses and only handles a hard-coded list of all possible control+letter combinations. I would prefer it if it would function without quirks, blocking caps lock pressed events, storing any other keys pressed while the caps lock key has not yet been released, and then deciding whether to send escape or control.

Is there a simple utility or a more generic AutoHotkey script that does this?

rationalis

Posted 2013-04-11T23:37:28.230

Reputation: 191

Question was closed 2013-04-15T06:36:44.660

The answer you posted to the other question also seems to not work with key chords. Specifically, it seems to work only with right shift. For example, I'm pressing CapsLock+Shift+Tab and trying to get Ctrl+Shift+Tab. Pressing CapsLock+LShift+Tab doesn't seem to generate anything at all, but CapsLock+RShift+Tab works fine. – rationalis – 2014-11-13T21:28:09.787

Not sure what's going wrong for you, but CapsLock+LShift+Tab works for me. (e.g. it successfully switches tabs in reverse order in Chrome.) I'm currently running on Windows 8.1 but I'm pretty sure it worked in Windows 7 and Windows 8, too. – Rich – 2014-11-14T10:13:57.147

FWIW, whilst I also don't like the answer I posted, I haven't ever experienced any issues with it in practice, so if the answer below isn't working for you (as you state in comments), it's worth trying out, at least. – Rich – 2013-12-16T10:13:41.720

Answers

13

This script registers a single press on CapsLock as a press that lasts less than 400ms, modify that value as needed.

*CapsLock::
    Send {Blind}{Ctrl Down}
    cDown := A_TickCount
Return

*CapsLock up::
    If ((A_TickCount-cDown)<400)  ; Modify press time as needed (milliseconds)
        Send {Blind}{Ctrl Up}{Esc}
    Else
        Send {Blind}{Ctrl Up}
Return

Elliot DeNolf

Posted 2013-04-11T23:37:28.230

Reputation: 843

works completely fine with ctrl+shift combinations for me. Thanks. – Mike H-R – 2014-10-02T12:54:08.050

For some reason, it doesn't work properly with multiple keystrokes, e.g. Ctrl+Shift+Tab or Ctrl+Alt+Del, although it works fine for 2-key combos like Ctrl-A or Ctrl-Tab. – rationalis – 2013-04-12T19:20:35.190

I was missing an * before the first CapsLock hotkey. The Ctrl+Shift combinations will work now. Ctrl+Alt+Del however is a special shortcut that cannot be sent from AutoHotkey. – Elliot DeNolf – 2013-04-12T19:49:09.737

The asterisk doesn't seem to have made any difference for me. – rationalis – 2013-04-12T21:06:41.247