How to use CapsLock as a modifier key in ahk v2 Topic is solved
Posted: 21 Jan 2024, 17:48
There's a few variants of this code posted on this forum. Just wanted to make it easier to find for everyone. The goal is to turn CapsLock into a proper modifying key, and not do simple combos like CapsLock & q:: MsgBox.
The good part about this is that the CapsLock functionality is preserved. Just double click CapsLock!
The good part about this is that the CapsLock functionality is preserved. Just double click CapsLock!
Code: Select all
CapsLock:: {
start := A_TickCount ; run once
KeyWait('CapsLock') ; wait for Capslock to be released
if (A_TickCount - start < 200) ; in 0.2 seconds
and KeyWait('CapsLock', 'D T0.2') ; and pressed again within 0.2 seconds
and (A_PriorKey = 'CapsLock') ; block other keys
SetCapsLockState !GetKeyState('CapsLock', 'T')
}
*CapsLock:: return ; This forces capslock into a modifying key.
#HotIf GetKeyState("CapsLock", "P")
Alt:: return ; Disables Alt menu when CapsLock + Alt is pressed.
LWin:: return ; Suppresses the Start Menu.
RWin:: return
; ---- Your hotkeys go here! ----
q:: MsgBox "You pressed CapsLock + q"
^w:: MsgBox "You pressed CapsLock + Control + w"
#HotIf