Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AutoHotkey script to map Caps Lock to Escape when it's pressed on its own and Ctrl when used in combination with another key, à la Steve Losh. Adapted from one that does something similar with the Ctrl Key on the Vim Tips Wiki ( (Plus contribs from @randy909 & @mmikeww.)
g_LastCtrlKeyDownTime := 0
g_AbortSendEsc := false
g_ControlRepeatDetected := false
if (g_ControlRepeatDetected)
send,{Ctrl down}
g_LastCtrlKeyDownTime := A_TickCount
g_AbortSendEsc := false
g_ControlRepeatDetected := true
*CapsLock Up::
send,{Ctrl up}
g_ControlRepeatDetected := false
if (g_AbortSendEsc)
current_time := A_TickCount
time_elapsed := current_time - g_LastCtrlKeyDownTime
if (time_elapsed <= 250)
SendInput {Esc}
g_AbortSendEsc := true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.