Skip to content

Instantly share code, notes, and snippets.

@githusr
Forked from sedm0784/CapsLockCtrlEscape.ahk
Last active September 14, 2025 16:35
Show Gist options
  • Select an option

  • Save githusr/7355e6038cd2af4b234fa9a9002f2c71 to your computer and use it in GitHub Desktop.

Select an option

Save githusr/7355e6038cd2af4b234fa9a9002f2c71 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.)
#Requires AutoHotkey 2.0.19 64-bit
#SingleInstance Force
; #NoTrayIcon
ProcessSetPriority "High"
LShift & RShift:: SetCapsLockState !GetKeyState("CapsLock", "T")
*CapsLock:: {
Send "{LCtrl down}"
LastCtrlKeyDownTime := A_TickCount
KeyWait "CapsLock"
Send "{LCtrl up}"
if A_PriorKey = "CapsLock" && A_TickCount - LastCtrlKeyDownTime <= 250 {
Send "{Esc}"
}
}
<!q::!F4
<!b::^b
<!f::^f
<!h::^h
<!n::^n
<!p::^p
*<^b:: Send "{Blind^}{Left}"
*<^f:: Send "{Blind^}{Right}"
*<^h:: Send "{Blind^}{BS}"
*<^n:: Send "{Blind^}{Down}"
*<^p:: Send "{Blind^}{Up}"
#HotIf WinActive("ahk_exe msedge.exe")
<^q::^Tab
<^Tab::^q
#HotIf
#e:: {
if WinExist(" - File Explorer") {
WinActivate
} else {
Run "explorer"
}
}
(defcfg
process-unmapped-keys (all-except ralt)
log-layer-changes false
concurrent-tap-hold true
notify-cfg-reload false
notify-cfg-reload-silent true
)
(defsrc)
(deftemplate emacs (src dst)
$src (switch
(lctl) (unmod (lctl) $dst) break
(lalt) (multi rctl (macro (unmod (lalt) $src))) break
() _ break
)
)
(deflayermap base
caps (tap-hold-press 200 200 esc lctl)
rsft (fork _ caps (lsft))
(t! emacs p up)
(t! emacs n down)
(t! emacs b lft)
(t! emacs f rght)
(t! emacs h bspc)
q (fork _ f4 (lalt))
s (fork _ (unmod f1) (lalt))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment