Here's an AHK script I've had since 2007 (omg, I'm too old). Adds a delay (press-and-hold to enable/disable) to capslock. Not exactly what you want, but I loved it and it should be easy to modify to do what you want:
CAPSLKTOOLTIP:
ToolTip,
SetTimer,CAPSLKTOOLTIP,Off
Return
SetTimer,CAPSLKTOOLTIP,1500
SetTimer,CAPSLKTOOLTIP,Off
CapsLock::
counter := 0
Loop,20
{
Sleep, 40
counter++
GetKeyState,state,CapsLock,P
If state=U
Break
If counter >= 20
{
counter := 0
GetKeyState,state,CapsLock,T
If state=D
{
ToolTip,Caps Lock Off
SetCapsLockState,Off
}
Else
{
ToolTip,Caps Lock On
SetCapsLockState,On
}
keyWait, Capslock, U
SetTimer,CAPSLKTOOLTIP,On
Continue
}
}
Return
- in a “caps lock key pressed” handler, set a timer (https://www.autohotkey.com/docs/v2/lib/SetTimer.htm) that runs every ten seconds
- in that timer, check the value of A_TimeIdleKeyboard (https://www.autohotkey.com/docs/v2/Variables.htm#TimeIdleKey...)
- if it’s too large, call SetCapsLockState (https://www.autohotkey.com/docs/v2/lib/SetNumScrollCapsLockS...) and stop the timer
- otherwise, compute a new ideal delay from the desired run interval and A_TimeIdleKeyboard, and update the time interval
You also wail want to prevent starting multiple timers if you enable caps lock multiple times.