Installation:
Copy into a function lib folder (for auto-#Inclusion) or use #Include manually. Note: Script must not be copy-pasted into the main script
Syntax: OnWin( event, WinTitle, callback )Parameter(s):
- event - Window event to monitor. Valid values are: Exist, Active, Show, Hide, Move, Minimize, Maximize, NotActive/!Active, Close/NotExist/!Exist, CloseAll/NotExistAll/!ExistAll
- WinTitle - see WinTitle. Due to limitations, ahk_group GroupName is not supported directly. To specify a window group, pass an array of WinTitle(s) instead. OnWin() uses A_TitleMatchMode and A_TitleMatchModeSpeed.
- callback - Function name, Func object or object. The callback will receive an event object with the ff properties: Event and Window, as its first argument.
Spoiler
Example Usage:
Code: Select all
#Include <OnWin>
#Persistent
OnWin("Exist", "Calculator", Func("C"))
Sleep, 1000
Run, calc.exe
return
C(this)
{
static window
event := this.Event, window := this.WinTitle
MsgBox, Event: %event%`nWindow: %window%
OnWin("Close", window, Func("X"))
SetTimer, close, -1000
return
close:
WinClose, %window%
return
}
X(this)
{
event := this.Event, window := this.WinTitle
MsgBox, Event: %event%`nWindow: %window%
SetTimer, exit, -1 ; allow function to return
return
exit:
ExitApp
}
Credits to Lexikos for demonstrating ObjRegisterActive and jNizM for CreateGUID. I have integrated some parts as needed.
Edit:[list][*]Bumped version to v1.0.03.00, see commit 151bda8 - 02/23/2015
[*]Updated to reflect commit 7878f45 - 02/21/2015
[*]Updated to reflect commit ab9052a - 02/19/2015[/list]