WinWaitClose blocking script

Get help with using AutoHotkey and its commands and hotkeys
Lem2001
Posts: 63
Joined: 27 Jun 2017, 17:59

WinWaitClose blocking script

21 Mar 2020, 19:05

I'm having an issue with WinWaitClose that I could use some help with.

I'm trying to create a basic script that uses an If / else type of structure, and within the 'if' part there is a WinWaitClose command that should only apply if the specified 'If' criteria are met.

However, I've found that the WinWaitClose command is actually blocking the 'else' part of my test script - which is what should be run in all other circumstances where the 'if' part of the script does not apply (and therefore the section containing WinWaitClose should not even be executed).

I don't have any usable code as yet (just a few broken experiments) because I'm still tying to get the basic structure right before I start plugging in specific bits of code and making things more complicated.

I'm trying to do something like this:

If a certain application is active, then pressing a hotkey opens a feature of the active application (which opens in a separate 'child' window) and WinWaitClose is used to wait for that child window to close, after which a command is executed (to delete some files). However, if the child window already exists when that same hotkey is pressed, it just switches focus to that child window instead of trying to launch the feature again that would (theoretically) result in another child window being opened.

There may be another 'If' nested within the first one (to perform different actions after the child window closes) but for the sake of simplicity I'll ignore that for now, so that I have a better chance of being able to understand what's going on structure-wise.

I have the necessary code to perform all the various individual tasks that I require, so that's not the issue; it's more a problem of 'structure' and how put the bits of code together (so as to not get unwanted side effects). If the hotkey is used once to launch the child window, then the WinWaitClose command will already be activated. So I guess any subsequent attempts to use the hotkey to re-focus the existing child window will be ignored because I AHK is probably stuck waiting for the child window to close from the first time that the hotkey was pressed.

If anyone is prepared to outline a basic code template / guide (to structure things in a way that prevents the problem described above) it would be very much appreciated.

My apologies for the vagueness of this post, but issues of structure are more difficult to frame as a question than simply asking how a certain AHK feature works.
User avatar
boiler
Posts: 5668
Joined: 21 Dec 2014, 02:44

Re: WinWaitClose blocking script

21 Mar 2020, 19:48

The best thing to do is to post the basic script that is not working (even if just an experiment) than for us to try to guess what’s wrong. It can’t get stuck on WinWaitClose if the associated if condition isn’t true unless you haven’t formatted it correctly such as not defining the code block after the if statement.
vsub
Posts: 470
Joined: 29 Sep 2015, 03:39

Re: WinWaitClose blocking script

22 Mar 2020, 07:36

It may be easier to help you if you post your code even if it's a failed attempt.

If try to press the hotkey the normal way(not with AHK)does it work as expected
"If a certain application is active, then pressing a hotkey opens a feature of the active application (which opens in a separate 'child' window)"
So you press the hotkey the normal way(no AHK)and that window appear
"However, if the child window already exists when that same hotkey is pressed, it just switches focus to that child window instead of trying to launch the feature again that would (theoretically) result in another child window being opened."
And if that child window exist and you press the hotkey again(no AHK)does it open the feature again(is it a new instance or second window)

AHK work this way...if you can do it with mouse and keyboard,AHK also will be able to do it.

Return to “Ask For Help”

Who is online

Users browsing this forum: anhnha, Bing [Bot], boiler, pnKed, SilasDeVis and 55 guests