Push a button - Two choices

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Push a button - Two choices

30 Aug 2015, 17:24

Hi!
My problem is
I have a button (Button1). When this button is pressed, two things can happen
Option1 - The window with the button is closing (Win1)
Option2 - Another window - (Win2) - is opening (over the Win1).

One way is to wait, a number of seconds, that the Win1 is to be closed.
But, if Win2 has opened, Win1 will never be closed.

Is the best way, to write a loop to make the solution?

Code: Select all

MessID = ahk_class ______ ahk_exe _______.exe	; Win1
ControlClick Button1, %MessID%	; Press the "Exit" button
Loop 5000
{    IfWinExist Win2  ; If Win2 is opened 
     {    Do .....
     }
     else {
         IfNotWinExist %MessID% 	; Win1 is closed
             Do ....
     }
     If A_Index = 5000
         MsgBox Nothing was happening under all 5000 loops
}
Is it possible to carry out this control in a better way?
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: Push a button - Two choices

30 Aug 2015, 19:29

I'm not sure what you want to do...

Code: Select all

win1_is_open := false
win2_is_open := false
timeout := 10000 ; 10 seconds

; when win1 is oppened, set win1_is_open := true

Loop {
if (win1_is_open) {
    ; do your stuff
}

if (win2_is_open) {
    ; do your stuff
}

sleep, 100
timeout--
if (timeout<=0)
   break

} while (win_1_is_open)
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Re: Push a button - Two choices

31 Aug 2015, 05:33

Thank you!
I think you have understood my problem.
I had an idea to use a "while-loop" (like this below)
Maybe it's more easy to do it on your way.

Code: Select all

Press "Button1"
While (Win1 exist) and (Win2 not exist)
{	Sleep 100
	If A_Index > 50	; 50 * 100 = 5 seconds
	{   This happen very seldom - or never
	    Manage "Nothing was happening when the button was pressed"
	}
}

if Exist Win2
{ Make some instructions on the Win2
  Close Win2
  Wait until Win2 is closed
}

While (Win1 exist)
{ Wait until Win1 not exist
...
}
Now, both Win1 and Win2 is closed.

move on in the program
But felt that the first "While expression" became a bit complicated for me.
And I think it's difficult to know if the instruction is
"IfWinExist WinName ahk_class ..... ahk_exe ....
or If WinExist("WinName ahk_class ...") - when and how quotes should be
For Example
If WinExist("WinName" "ahk_class ...." ahk_exe ....") or
If WinExist("WinName ahk_class .... ahk_exe ....")

//Jan
Azevedo
Posts: 81
Joined: 07 Feb 2014, 11:35

Re: Push a button - Two choices

31 Aug 2015, 09:59

Code: Select all

win1_is_open := false
win2_is_open := false
timeout := 10000 ; 10 seconds

Gui, add, button. gCheckWindows, Check windows
Gui, show



return

checkWindows:

Loop {

if (win1_is_open) && (win2_is_open) {

   WinClose, YourWndow Title
   Loop { ; wait for win2 to close
      if (!win2_is_open)
          break
      sleep, 100
      timeout--
   }

sleep, 100
timeout--
if (timeout<=0)
   break
 
} while (win_1_is_open)

return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 178 guests