Adapted from Josh Brobst on Stack Overflow
#include
this script. This creates two object declarations, WindowChangeDetector and Debug_Gui, and one super global variable, ChangeDetector.- Create a new instance of a WindowChangeDetector. This takes two parameters:
- A declared AHK function that will be the callback for when a window changes
- An optional boolean
debug
that controls whether a window will be created for logging debug messages.
[optional] ifNot working, see limitationsdebug == True
, log debugging messages to the debug window by calling the instance methoddebug(msg)
Example:
#include %A_ScriptDir%\ahk-detect_window_change\onWindowChange.ahk
changeDetector := new WindowChangeDetector("msgboxActiveWindow", True)
msgboxActiveWindow(){
global changeDetector
WinGetActiveTitle, ThisWindow
changeDetector.debug("Active: '" ThisWindow "'")
msgbox % ThisWindow
}
Adds three global objects to script:
WindowChangeDetector
object declarationDebug_Gui
object declarationChangeDetector
superglobal object (available to all functions by default, can be overridden).
Causes the including script to become:
- persistent
- single-instance
Code run by the callback does not have access to the instance variables, so using the debugging window fails. Use a msgbox to confirm the callback works.