WinWaitActive - speed setting? Topic is solved
WinWaitActive - speed setting?
How often does WinWaitActive "refresh" its check? Is there a way to speed it up? I want to handle a popup window but it still flickers visbly on the screen before autohotkey can put input in a control and then press a button to close it. Is there some other way to handle it quicker?
Re: WinWaitActive - speed setting?
Not really sure, perhaps you can try SetWinDelay
Re: WinWaitActive - speed setting?
I don't know about quicker but you can instead of WinWaitActive, use a timer with your own period, or a loop with a sleep period or without it, and use WinActive() or WinExist() for your waiting
that's operating on your own time, yet it's about how you implement it.
that's operating on your own time, yet it's about how you implement it.
Re: WinWaitActive - speed setting? Topic is solved
Instead of polling for the active window and check if it has changed since last time, you can let Windows tell you when a new window is created or the active window changes. This event triggers when the window has been created, but is perhaps not yet visible. The OnMessage causes interruption of running code. So you have a higher chance it's too fast than too slow.
Try it and listen to the different beeps upon activation or creation, Escape ends the script.
Code: Select all
ShellMessage(wParam, lParam:=""){
static init:=DllCall("RegisterShellHookWindow", UInt,A_ScriptHwnd)
,MsgNum:=OnMessage(DllCall("RegisterWindowMessage", Str,"SHELLHOOK"), "ShellMessage")
,cleanup:={base:{__Delete: "ShellMessage"}}
;Deregister shell hook
if !(cleanup)
return DllCall("DeregisterShellHookWindow","Ptr",A_ScriptHwnd), OnMessage( MsgNum, "" )
WinGetTitle, WinTitle, ahk_id %lParam%
WinGetClass, WinClass, ahk_id %lParam%
;New window created
If (wParam=1){ ;HSHELL_WINDOWCREATED:=1
SoundBeep, 2200, 400
MsgBox, % "Dectected window creation.`n`nTitle:`t`t" WinTitle "`nahk_class:`t`t" WinClass
;Change of active window
}Else If (wParam=4 || wParam=32772){ ;HSHELL_WINDOWACTIVATED:=4 , 32772 == HSHELL_RUDEAPPACTIVATED:=32772 (fullscreen app active)
SoundBeep, 1200, 200
}
}
Esc::ExitApp
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: WinWaitActive - speed setting?
Can someone post a sample of using this? I know the title I am expecting (Shipping Schedule) and I know the ahk_class (I do not know the hwnd yet because the window has not been created yet).Nextron wrote: ↑15 Feb 2015, 13:43Instead of polling for the active window and check if it has changed since last time, you can let Windows tell you when a new window is created or the active window changes. This event triggers when the window has been created, but is perhaps not yet visible. The OnMessage causes interruption of running code. So you have a higher chance it's too fast than too slow.Try it and listen to the different beeps upon activation or creation, Escape ends the script.Code: Select all
ShellMessage(wParam, lParam:=""){ static init:=DllCall("RegisterShellHookWindow", UInt,A_ScriptHwnd) ,MsgNum:=OnMessage(DllCall("RegisterWindowMessage", Str,"SHELLHOOK"), "ShellMessage") ,cleanup:={base:{__Delete: "ShellMessage"}} ;Deregister shell hook if !(cleanup) return DllCall("DeregisterShellHookWindow","Ptr",A_ScriptHwnd), OnMessage( MsgNum, "" ) WinGetTitle, WinTitle, ahk_id %lParam% WinGetClass, WinClass, ahk_id %lParam% ;New window created If (wParam=1){ ;HSHELL_WINDOWCREATED:=1 SoundBeep, 2200, 400 MsgBox, % "Dectected window creation.`n`nTitle:`t`t" WinTitle "`nahk_class:`t`t" WinClass ;Change of active window }Else If (wParam=4 || wParam=32772){ ;HSHELL_WINDOWACTIVATED:=4 , 32772 == HSHELL_RUDEAPPACTIVATED:=32772 (fullscreen app active) SoundBeep, 1200, 200 } } Esc::ExitApp
So what would I put in the script to wait for this?
Re: WinWaitActive - speed setting?
Try the Modification of Nextron's code below. If you have a better method for handling the popup than WinClose, you can replace those lines with your approach. Also, since you only indicated the title, that's all I used to identify the window. You can add the ahk_class as well so you don't end up closing similarly named windows.
Code: Select all
ShellMessage(0)
return
ShellMessage(wParam, lParam:=""){
static init:=DllCall("RegisterShellHookWindow", UInt,A_ScriptHwnd)
,MsgNum:=OnMessage(DllCall("RegisterWindowMessage", Str,"SHELLHOOK"), "ShellMessage")
,cleanup:={base:{__Delete: "ShellMessage"}}
;Deregister shell hook
if !(cleanup)
return DllCall("DeregisterShellHookWindow","Ptr",A_ScriptHwnd), OnMessage( MsgNum, "" )
WinGetTitle, WinTitle, ahk_id %lParam%
WinGetClass, WinClass, ahk_id %lParam%
;New window created
If (wParam=1){ ;HSHELL_WINDOWCREATED:=1
if (WinTitle = "Shipping Schedule")
WinClose, ahk_id %lParam%
;Change of active window
}Else If (wParam=4 || wParam=32772){ ;HSHELL_WINDOWACTIVATED:=4 , 32772 == HSHELL_RUDEAPPACTIVATED:=32772 (fullscreen app active)
if (WinTitle = "Shipping Schedule")
WinClose, ahk_id %lParam%
}
}
Esc::ExitApp
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: WinWaitActive - speed setting?
Thank you. I couldn't figure out why it was failing. I looked at winspy at the class of the window I am trying to close and I see it is the same like a save as window! ahk_class #32770 the script maybe does not see this as a new window even when I specified the title
Re: WinWaitActive - speed setting?
You might want to try it with the check of the class also, as shown below. That way another window you might have open also named "Shipping Schedule" (could happen!) doesn't get closed.
Code: Select all
ShellMessage(0)
return
ShellMessage(wParam, lParam:=""){
static init:=DllCall("RegisterShellHookWindow", UInt,A_ScriptHwnd)
,MsgNum:=OnMessage(DllCall("RegisterWindowMessage", Str,"SHELLHOOK"), "ShellMessage")
,cleanup:={base:{__Delete: "ShellMessage"}}
;Deregister shell hook
if !(cleanup)
return DllCall("DeregisterShellHookWindow","Ptr",A_ScriptHwnd), OnMessage( MsgNum, "" )
WinGetTitle, WinTitle, ahk_id %lParam%
WinGetClass, WinClass, ahk_id %lParam%
;New window created
If (wParam=1){ ;HSHELL_WINDOWCREATED:=1
if (WinTitle = "Shipping Schedule") && (WinClass = "#32770")
WinClose, ahk_id %lParam%
;Change of active window
}Else If (wParam=4 || wParam=32772){ ;HSHELL_WINDOWACTIVATED:=4 , 32772 == HSHELL_RUDEAPPACTIVATED:=32772 (fullscreen app active)
if (WinTitle = "Shipping Schedule") && (WinClass = "#32770")
WinClose, ahk_id %lParam%
}
}
Esc::ExitApp
Who is online
Users browsing this forum: No registered users and 362 guests