Skip to content

Instantly share code, notes, and snippets.

@jarileskinen
Created December 27, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarileskinen/ff5065621fe0fd1896dcb1fdd3ea7174 to your computer and use it in GitHub Desktop.
Save jarileskinen/ff5065621fe0fd1896dcb1fdd3ea7174 to your computer and use it in GitHub Desktop.
AutoHotkey - Caps Lock to Ctrl and Escape
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Make Caps lock have the following behavior:
; - Short press (less than 0.4 seconds): send Escape key.
; - Press and hold: Holds down Control key.
CapsLock::
Send, {Ctrl down}
KeyWait, CapsLock, T0.4
if ErrorLevel { ; Timed-out.
KeyWait, CapsLock
Send, {Ctrl up}
}
else { ; Caps lock was released within 0.4 s.
if (A_PriorKey = "CapsLock") {
Send, {Ctrl up}
Send, {Esc}
}
else {
Send, {Ctrl up}
}
}
return
+CapsLock::
Send, {Shift down}{Ctrl down}
KeyWait, CapsLock
Send, {Shift up}{Ctrl up}
!CapsLock::
Send, {Alt down}{Ctrl down}
KeyWait, CapsLock
Send, {Alt up}{Ctrl up}
#CapsLock::
Send, {Win down}{Ctrl down}
KeyWait, CapsLock
Send, {Win up}{Ctrl up}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment