Skip to content

Instantly share code, notes, and snippets.

@JoeGlines
Created April 10, 2026 13:08
Show Gist options
  • Select an option

  • Save JoeGlines/3924222799673cce74f80c7b1dd72d47 to your computer and use it in GitHub Desktop.

Select an option

Save JoeGlines/3924222799673cce74f80c7b1dd72d47 to your computer and use it in GitHub Desktop.
lets the user know Capslock is on
#Requires AutoHotkey v2.0.2+
#SingleInstance Force ; Limit one running version of this script
; --- Settings ---
notifyTime := 10 ; how long (in seconds) CapsLock must be on before alerting
; --- State tracking ---
capsOnTime := 0 ; stores the tick count (ms) when CapsLock turned on; 0 means it's currently off
lastAlert := 0 ; stores the tick count of the most recent audio alert
; Check CapsLock state every 500ms — fast enough to catch it without hammering the CPU
SetTimer(CheckCapsLock, 500)
CheckCapsLock() {
global notifyTime, capsOnTime, lastAlert
if GetKeyState("CapsLock", "T") { ; "T" checks the toggle state (on/off), not whether the key is held
if capsOnTime = 0 ; CapsLock just turned on — record the start time
capsOnTime := A_TickCount
elapsed := A_TickCount - capsOnTime ; how many ms CapsLock has been on
; Fire an alert if:
; 1) CapsLock has been on longer than notifyTime seconds, AND
; 2) Enough time has passed since the last alert (so it repeats on the same interval)
if elapsed > notifyTime * 1000 && (A_TickCount - lastAlert) > notifyTime * 1000 {
SoundBeep(1200, 150) ; three short high-pitched beeps as the audio warning
SoundBeep(1200, 150)
SoundBeep(1200, 150)
lastAlert := A_TickCount ; update the last-alerted timestamp
}
} else { ; CapsLock is OFF — clear all tracking so the clock resets
capsOnTime := 0
lastAlert := 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment