How to use CapsLock as a modifier key in ahk v2

Helpful script writing tricks and HowTo's
iseahound
Posts: 1450
Joined: 13 Aug 2016, 21:04
Contact:

How to use CapsLock as a modifier key in ahk v2

Post by iseahound » 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!

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")
q:: MsgBox "You pressed CapsLock + q"
^w:: MsgBox "You pressed CapsLock + Control + w"
#HotIf

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: How to use CapsLock as a modifier key in ahk v2

Post by submeg » 03 Feb 2024, 05:04

Just wanted to make it easier to find for everyone
Can this be pinned somewhere?

I've been making mods to this script by Skommel - CapShift. Very nice!
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

Post Reply

Return to “Tutorials (v2)”