IfWinExist/Active /() reports false for active window
i haven't reported this because it only happens sporadically (but often enough to be annoying) and i don't know how to reproduce it. the only thing that i've noticed is that it seems to happen more when a window is switching or closing, or a new one is comming up - i.e. when windows are changing
is this an AutoHotkey bug?
You may want to strategically place one of two things:
1. WinWait (or WinWaitActive) - preferred
2. Sleep
It does not sound like a bug, but I may be wrong.
a window that i'm looking at
could read:
a window that i'm using and looking at i.e. the active window
but doesn't really need to be because even with a new window that's coming up, it's long since registered (a second or 2) by the time you see the gui
sometimes a script doesn't work correctly and when i look at the ListLines a IfWinExist/Active /WinExist/Active() statement evaluates false for a window that i'm looking at
i haven't reported this because it only happens sporadically (but often enough to be annoying) and i don't know how to reproduce it. the only thing that i've noticed is that it seems to happen more when a window is switching or closing, or a new one is comming up - i.e. when windows are changing
is this an AutoHotkey bug?
post the code - otherwise it's impossible to say whether the bug is in AHK rather than your scripting lest other analogous reports emerge...
Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet
If the problem persists, you could try a higher setting for SetWinDelay such as: SetWinDelay 500
If that doesn't help, if you can ever find a script that reproduces the problem, please post it here.
Thanks.
632: IfWinExist,Customize Notifications ahk_class #32770
633: ControlClick,OK,,,,,NA (0.03)
634: WinWaitClose,,,10 (0.13)
635: IfWinExist,Customize Notifications ahk_class #32770
636: MsgBox,32,%0_ScriptName% - %A_LineNumber%,'Customize Notifications' still exists (11.83)it seems to be happening this way more than the other - false reporting of windows existing when they've closed, or at least after being reported to be so by WinWait*. sometimes it seems as if WinWait is working correctly. (in this case it clearly isn't)
in a related but separata issue - ControlClick,OK worked this time but the several times previous to this (in the last hour) it's been pushing the &Restore Defaults button. (should this be a seperate post?)
If the problem with WinWaitClose persists, maybe try it with a simpler window like Notepad to ensure there really is a bug. This would also help to reproduce the issue on other PCs.To improve reliability -- especially during times when the user is physically moving the mouse during the ControlClick -- one or both of the following may help:
1) Use SetControlDelay -1 prior to ControlClick. This avoids holding the mouse button down during the click, which in turn reduces interference from the user's physical movement of the mouse.
2) Specify the string NA anywhere in the sixth parameter (Options) as shown below:SetControlDelay -1 ControlClick, Toolbar321, WinTitle,,,, NA"NA" avoids marking the target window as active and avoids merging its input processing with that of the script, which may prevent physical movement of the mouse from interfering (but usually only when the target window is not active). However, this method might not work for all types of windows and controls.
Thanks.
it seems to be happening this way more than the other - false reporting of windows existing when they've closed, or at least after being reported to be so by WinWait*. sometimes it seems as if WinWait is working correctly. (in this case it clearly isn't)
should read:
it seems to be happening this way more than the other - false reporting of windows existing when they've closed, or at least after being reported to be so by WinWaitClose. sometimes it seems as if WinWaitClose isn't working correctly. (in this case it clearly isn't)
i just put this together with only some preliminary testing (more testing later if needed)
unlike in the listing above, IfWinExist will always evaluate false after this function unless it times out
WinWaitClose( WinTitle = "", Seconds = 0) { StartTC := A_TickCount While WinExist(WinTitle) and (Seconds = 0) + (A_TickCount < (StartTC + (1000 * Seconds))) sleep A_WinDelay a := (Seconds = 0) + (A_TickCount < (StartTC + (1000 * Seconds))) if a = 0 ; it timed out ErrorLevel := Seconds return a ; 1/true on success (WinTitle no longer exists), 0/false if it still exists after Seconds seconds } if WinWaitClose(WinTitle, 10) a = %WinTitle% is closed else a = %WinTitle% is not closed after %ErrorLevel% seconds
So if you still have reason to believe that WinWaitClose isn't working properly, there would need to be some way to reproduce it (perhaps using a common window like Notepad).
Thanks.
the WinExist() in WinWaitClose had to incorrectly return false to break the loop (which surprised me because the Customize Notifications window was still showing) and in the next line IfWinExist correctly returned true for the same window
i've already stated that i don't know how to reproduce this problem - you probably need a hardcore testing guru for that (which i am most definitely not)
the listing was the 1st time after your (Chris) post that i was able to catch it in the act - i was debugging a script that would normally already be closed and therefor no ListLines. most of my scripts are context sensitive and load/close with a window/group of windows, and i have to put them in debug mode to be able to see ListLines after their windows are gone.
there have been many times over the course of at least a couple of years that i have seen WinWaitClose return true (continue without timing out) in ListLines when the window still existed/showed (especially with IE7 with tabs). it's been a big enough problem that in one of my scripts i have a 1 sec run-once timer to double-check it, since it was failing so often. it still fails every once in a while which means that WinWaitClose fails 2 times, a second apart, while i'm looking at the window (IE7 tab in this case) that it is reporting as closed.
i believe that IE7 is a "common window" - i don't use NotePad
i will post more lines when i can catch a script in the act again
IfWinExist: if_condition = (WinExist(*g, FOUR_ARGS, false, true) != NULL)
WinExist(): WinExist(*g, param[0], param[1], param[2], param[3], false, true)
Therefore, what you're probably seeing is some kind of split-second timing issue where the OS in one instant reports that the window exists, but in the next instant that it doesn't exist. Perhaps this can happen if an application (or the OS) recreates a window by destroying and recreating a nearly-identical window. I'm not sure why it would do that, but stranger things have happened. Maybe it has something to do with Vista Aero or process privileges (e.g. admin rights).
If you or anyone else ever finds out more about it, please post here.
Thanks.
i thought that's the case until some script behavior seemed to indicate otherwise (it makes no sense for them to be different)Internally IfWinExist and WinExist() call the same code
is there any possibility that WinWaitClose after ControlClick and without parameters is resetting LFW?
would there be any advantage to change it to:
634: WinWaitClose,Customize Notifications ahk_class #32770,, 10
the only reason for IfWinExist in line 632 is to set it, and it was faster/easier in PSpad to dup the line in 635
i'm running XP
It seems unlikely, but if you suspect it's true, it might not be hard to make a script that tests the behavior against simple windows like Notepad or Calculator.is there any possibility that WinWaitClose after ControlClick and without parameters is resetting LFW?
That would be more reliable if there's any chance that the last found window has been destroyed or recreated since it was set.would there be any advantage to change it to:
634: WinWaitClose,Customize Notifications ahk_class #32770,, 10