Skip to content

Instantly share code, notes, and snippets.

@brombres
Last active September 27, 2023 03:12
Show Gist options
  • Save brombres/e1d9a53ff915653a87b91efb7a3db33f to your computer and use it in GitHub Desktop.
Save brombres/e1d9a53ff915653a87b91efb7a3db33f to your computer and use it in GitHub Desktop.
AutoHotkey 2.0 Caps Lock to Escape and Control (Windows)
#Requires AutoHotkey v2.0
#SingleInstance
; Caps Lock is ESC if tapped (pressed and quickly released).
; Caps Lock is CTRL if held down.
; Install AHK 2: https://www.autohotkey.com
; Create CapsLock-to-ESC-and-CTRL.ahk in Startup containing this code.
; (File Explorer/Dialog > type in: Startup)
; Double-click to run
; Will auto-run next startup
global cDown := 0
; Hold down RIGHT CTRL and tap CAPS LOCK to toggle CapsLock
>^CapsLock::CapsLock
; CapsLock is pressed - send CTRL Down
CapsLock::
{
Send "{Blind}{Ctrl Down}"
global cDown := A_TickCount
}
; CapsLock is released - send CTRL Up.
; Also send ESCAPE if the press & release was quick enough.
CapsLock up::
{
; Modify the threshold time (in milliseconds) as necessary
if ((A_TickCount-cDown) < 150)
{
Send "{Blind}{Ctrl Up}{Esc}"
}
else
{
Send "{Blind}{Ctrl Up}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment