Last active
October 12, 2025 05:46
-
Star
(263)
You must be signed in to star a gist -
Fork
(52)
You must be signed in to fork a gist
-
-
Save sedm0784/4443120 to your computer and use it in GitHub Desktop.
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 (http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_Windows?oldid=32281). (Plus contribs from @randy909 & @mmikeww.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| g_LastCtrlKeyDownTime := 0 | |
| g_AbortSendEsc := false | |
| g_ControlRepeatDetected := false | |
| *CapsLock:: | |
| if (g_ControlRepeatDetected) | |
| { | |
| return | |
| } | |
| send,{Ctrl down} | |
| g_LastCtrlKeyDownTime := A_TickCount | |
| g_AbortSendEsc := false | |
| g_ControlRepeatDetected := true | |
| return | |
| *CapsLock Up:: | |
| send,{Ctrl up} | |
| g_ControlRepeatDetected := false | |
| if (g_AbortSendEsc) | |
| { | |
| return | |
| } | |
| current_time := A_TickCount | |
| time_elapsed := current_time - g_LastCtrlKeyDownTime | |
| if (time_elapsed <= 250) | |
| { | |
| SendInput {Esc} | |
| } | |
| return | |
| ~*^a:: | |
| ~*^b:: | |
| ~*^c:: | |
| ~*^d:: | |
| ~*^e:: | |
| ~*^f:: | |
| ~*^g:: | |
| ~*^h:: | |
| ~*^i:: | |
| ~*^j:: | |
| ~*^k:: | |
| ~*^l:: | |
| ~*^m:: | |
| ~*^n:: | |
| ~*^o:: | |
| ~*^p:: | |
| ~*^q:: | |
| ~*^r:: | |
| ~*^s:: | |
| ~*^t:: | |
| ~*^u:: | |
| ~*^v:: | |
| ~*^w:: | |
| ~*^x:: | |
| ~*^y:: | |
| ~*^z:: | |
| ~*^1:: | |
| ~*^2:: | |
| ~*^3:: | |
| ~*^4:: | |
| ~*^5:: | |
| ~*^6:: | |
| ~*^7:: | |
| ~*^8:: | |
| ~*^9:: | |
| ~*^0:: | |
| ~*^Space:: | |
| ~*^Backspace:: | |
| ~*^Delete:: | |
| ~*^Insert:: | |
| ~*^Home:: | |
| ~*^End:: | |
| ~*^PgUp:: | |
| ~*^PgDn:: | |
| ~*^Tab:: | |
| ~*^Return:: | |
| ~*^,:: | |
| ~*^.:: | |
| ~*^/:: | |
| ~*^;:: | |
| ~*^':: | |
| ~*^[:: | |
| ~*^]:: | |
| ~*^\:: | |
| ~*^-:: | |
| ~*^=:: | |
| ~*^`:: | |
| ~*^F1:: | |
| ~*^F2:: | |
| ~*^F3:: | |
| ~*^F4:: | |
| ~*^F5:: | |
| ~*^F6:: | |
| ~*^F7:: | |
| ~*^F8:: | |
| ~*^F9:: | |
| ~*^F10:: | |
| ~*^F11:: | |
| ~*^F12:: | |
| g_AbortSendEsc := true | |
| return |
For authohotkey v2: https://gist.github.com/108anup/ecd891f21dc88ef107ff6c8ab0969700
Working wiki link at head (without needing to login) https://vim.fandom.com/wiki/Map_caps_lock_to_escape_in_Windows
Working wiki link at head (without needing to login) https://vim.fandom.com/wiki/Map_caps_lock_to_escape_in_Windows
Dual Key Remap is awesome.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to run this script, you should look into AutoHotKey. in this example, you need to install the correct version of the runtime, save the script as an .auk file, and run it using the runtime.