Skip to content

Instantly share code, notes, and snippets.

@4piu
Created January 17, 2026 03:19
Show Gist options
  • Select an option

  • Save 4piu/c7cd24545c3ebd6c431f901b744d65ee to your computer and use it in GitHub Desktop.

Select an option

Save 4piu/c7cd24545c3ebd6c431f901b744d65ee to your computer and use it in GitHub Desktop.
AutoHotKey example: hotkey activated loop, skip if window not in focus.
#Requires AutoHotkey v2.0
#SingleInstance Force
#MaxThreadsPerHotkey 2
windowTitle := "ahk_exe notepad.exe"
#HotIf WinActive(windowTitle)
+F1:: {
static running := false
running := !running
TrayTip(running ? "Running" : "Stopped")
SetTimer TimedLoop, running ? 1000 : 0
}
TimedLoop() {
if (!WinActive(windowTitle)) {
return
}
Send "{C down}"
Send "{C up}"
Send "{N down}"
Send "{N up}"
Send "{M down}"
Send "{M up}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment