Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active August 29, 2015 14:11
Show Gist options
  • Save cowboy/77642d25ef49559d574f to your computer and use it in GitHub Desktop.
Save cowboy/77642d25ef49559d574f to your computer and use it in GitHub Desktop.
AutoHotKey: Poll system for known active windows
; ===================================================
; Poll system for known active windows
; "Cowboy" Ben Alman - 2014
; https://gist.github.com/cowboy/77642d25ef49559d574f
; ===================================================
#Persistent
#SingleInstance Force
; Exe windows to poll for.
ExeCount = 3
Exe1 = calc.exe
Exe2 = explorer.exe
Exe3 = chrome.exe
LastExe := false
SetTimer CheckActive, 100
CheckActive:
Loop %ExeCount% {
CurrentExe := Exe%A_Index%
if (WinActive("ahk_exe" CurrentExe)) {
if (CurrentExe != LastExe) {
LastExe := CurrentExe
ActivateProfile(CurrentExe)
}
Return
}
}
if (LastExe != false) {
LastExe := false
ActivateProfile()
}
Return
ActivateProfile(Exe = false) {
if (Exe) {
TrayTip Active, %Exe%, 0
} else {
TrayTip Inactive, No exe detected, 0
}
; Do actual stuff here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment