Multiple winclose windows

Get help with using AutoHotkey and its commands and hotkeys
hannahelappin
Posts: 53
Joined: 01 Jun 2019, 09:02

Multiple winclose windows

02 Aug 2019, 10:16

Hi,

I want multiple sofware pop up boxes to automatically close. Works for the first "Warning" window but not the next.
Loop
{
WinWait, Warning
WinClose, Warning
}


Loop
{
WinWait, information
WinClose, information
} Any help much appreciated.
GEV
Posts: 817
Joined: 25 Feb 2014, 00:50

Re: Multiple winclose windows

02 Aug 2019, 10:40

Best solution (in my opinion):

Code: Select all

GroupAdd, Unwanted_Windows, Warning
GroupAdd, Unwanted_Windows, information

Loop
{
	WinWait, ahk_group Unwanted_Windows
	WinClose
}
Alibaba
Posts: 479
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Multiple winclose windows

03 Aug 2019, 07:04

Hello hannahelappin,

just to clarify a bit why your current solution is not working: Your script will never leave the first loop, so the second loop is “dead code”.

A (unconditional) loop like you are using will only be exited by instructing the script to do so. Take a look at the break statement.

I recommend GEVs solution.
"Nothing is quieter than a loaded gun." - Heinrich Heine
Sid4G
Posts: 49
Joined: 02 Apr 2016, 19:11

Re: Multiple winclose windows

03 Aug 2019, 09:12

Alibaba wrote:
03 Aug 2019, 07:04
Hello hannahelappin,

just to clarify a bit why your current solution is not working: Your script will never leave the first loop, so the second loop is “dead code”.

A (unconditional) loop like you are using will only be exited by instructing the script to do so. Take a look at the break statement.

I recommend GEVs solution.
So using groups it loops automatically without having to write the sequence manually?
Alibaba
Posts: 479
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Multiple winclose windows

03 Aug 2019, 11:03

Sid4G wrote:
03 Aug 2019, 09:12
So using groups it loops automatically without having to write the sequence manually?
Well you could think of it like that if it makes it easy to understand, but how WinWait does this internally depends on its implementation in the AHK source code. Using a loop to repeatedly check a condition is called busy waiting (link fyi) but I guess that WinWait is based on system events instead. You should avoid busy waiting whenever possible. (While again this doesn't always apply for low-level programming and use cases :P )
"Nothing is quieter than a loaded gun." - Heinrich Heine
Sid4G
Posts: 49
Joined: 02 Apr 2016, 19:11

Re: Multiple winclose windows

03 Aug 2019, 15:57

Alibaba wrote:
03 Aug 2019, 11:03
Sid4G wrote:
03 Aug 2019, 09:12
So using groups it loops automatically without having to write the sequence manually?
Well you could think of it like that if it makes it easy to understand, but how WinWait does this internally depends on its implementation in the AHK source code. Using a loop to repeatedly check a condition is called busy waiting (link fyi) but I guess that WinWait is based on system events instead. You should avoid busy waiting whenever possible. (While again this doesn't always apply for low-level programming and use cases :P )
Busy waiting or... a game 8-)
hannahelappin
Posts: 53
Joined: 01 Jun 2019, 09:02

Re: Multiple winclose windows

04 Aug 2019, 14:42

GEV, Alibaba that’s great guys thanks a lot. I’m new to this and I guessed that my second loop was dead code. Just was a bit lazy really copying something I’d read on another site.

Many thanks for your help that script works great 👍

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], boiler, Hackerxd, Odlanir, WantToKnow, Yakshongas, yodo and 114 guests