Skip to content

Lets autohotkey scripts be notified when the currently active window changes

License

Notifications You must be signed in to change notification settings

BlueDrink9/ahk-detect_window_change

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Adapted from Josh Brobst on Stack Overflow

Usage

  1. #include this script. This creates two object declarations, WindowChangeDetector and Debug_Gui, and one super global variable, ChangeDetector.
  2. Create a new instance of a WindowChangeDetector. This takes two parameters:
    1. A declared AHK function that will be the callback for when a window changes
    2. An optional boolean debug that controls whether a window will be created for logging debug messages.
  3. [optional] if debug == True, log debugging messages to the debug window by calling the instance method debug(msg) Not working, see limitations

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 declaration
  • Debug_Gui object declaration
  • ChangeDetector superglobal object (available to all functions by default, can be overridden).

Causes the including script to become:

  • persistent
  • single-instance

Known limitations

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.

About

Lets autohotkey scripts be notified when the currently active window changes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published