Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

wait till window opens then wait till it closes


  • Please log in to reply
9 replies to this topic
toop
  • Guests
  • Last active:
  • Joined: --
I have 2 scenarios I'm struggling with

Scenario 1:
step1.click a button
step2.then after .5seconds a dialog box *may* appear
step3.if it does appear then send ENTER
step4.now regardless of whether the dialog in step 2/3 appeared, a different dialog box will now appear, press TAB then ENTER on this dialog

Scenario 2:
The title of the main application is called blah
Step1.click a button
step2.then after .5seconds, 2 dialog boxs will appear. So there will be 3 windows of this application open. The main app window called blah, a new window in the background called other and then a smaller active window called blah (same title as the main application)
step3.the 2 new dialogs from step 2 may take between 10seconds and 2 minutes before they both closes by themself
step4.once those 2 windows from step3 close i wan't to send Shift + C

Can someone please provide the code?

Thanks in advance!

bhawk
  • Members
  • 15 posts
  • Last active: Jan 19 2014 08:21 PM
  • Joined: 09 Mar 2009
Let us see what you have done till now...

  • Guests
  • Last active:
  • Joined: --
scenario 1:
IfWinActive, Warning - Opening Old Project File
{
SendInput {Enter}
}


scenario 2:
WinWaitClose, ahk_class #32770
Sleep, 1000
Send +C


for the first scenario, it seems to work
but for the 2nd scenario it never sends the Shift + C (because if it did a save window would then appear)

bump
  • Guests
  • Last active:
  • Joined: --
bump

bhawk
  • Members
  • 15 posts
  • Last active: Jan 19 2014 08:21 PM
  • Joined: 09 Mar 2009
Is that what you need for scenario 1?


IfWinActive, Warning - Opening Old Project File 
{ 
SendInput {Enter} 
} 
sleep 500
SendInput {Tab} 
sleep 100
SendInput {Enter}


  • Guests
  • Last active:
  • Joined: --

Is that what you need for scenario 1?


IfWinActive, Warning - Opening Old Project File 
{ 
SendInput {Enter} 
} 
sleep 500
SendInput {Tab} 
sleep 100
SendInput {Enter}


THanks but this does not check for the 2nd dialog box appearing
also, scenario 2 is the real challenge.

bhawk
  • Members
  • 15 posts
  • Last active: Jan 19 2014 08:21 PM
  • Joined: 09 Mar 2009
first let's finish with scenario 1, then we will move to scenario 2

IfWinActive, Warning - Opening Old Project File 
{ 
SendInput {Enter} 
} 
sleep 500
IfWinActive, <your new opened windows>
{
SendInput {Tab} 
sleep 100
SendInput {Enter}
}

[/code]

CodeKiller
  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008
/*

Scenario 1: 

step1.click a button 

step2.then after .5seconds a dialog box *may* appear 

step3.if it does appear then send ENTER 

step4.now regardless of whether the dialog in step 2/3 appeared, a different dialog box will now appear, press TAB then ENTER on this dialog 

*/



WinWaitActive Window1

Send {Return} ; Valdiate the current window, ok if the windows contains a single button

SetTimer CheckPopup, 100

WinWaitActive Window2

Send {Tab}{Return}



Return



CheckPopup:

IfWinExist Popup

{

	WinActivate Popup

	Send {Return}

	SetTimer Popup2, Off

}

Return


CodeKiller
  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008
/*

Scenario 2: 

The title of the main application is called blah 

Step1.click a button 

step2.then after .5seconds, 2 dialog boxs will appear. So there will be 3 windows of this application open. The main app window called blah, a new window in the background called other and then a smaller active window called blah (same title as the main application) 

step3.the 2 new dialogs from step 2 may take between 10seconds and 2 minutes before they both closes by themself 

step4.once those 2 windows from step3 close i wan't to send Shift + C

*/



WinWaitActive blah

Send {Return} ; same thing as scenario 1, that's depend of the number of buttons in the window, if it's a yes/no you must use some tabs or ControlClick

Wait := True

SetTimer WaitToClose, 100

While Wait

	Sleep 100

Send ^c



Return



WaitToClose:

	IfWinExist other

		other := True

	IfWinExist blah ; THIS WON'T WORK ! You should check the ahk_class of the second "blah" window or something to identify it (some text specific to the window perhaps)

		blah := True

	If other And !WinExist("other")

		otherClosed := True

	If blah  And !WinExist("blah") ; Same thing as above

		blahClose := True

	If (otherClosed And blahClose)

		Wait := False ; This should stop the loop in the main code

	If !Wait

		SetTimer WaitToClose, Off

Return


CodeKiller
  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008
Working example with the scenario 2 and Notepad :
WinWaitActive ahk_class Notepad
Sleep 100
Send This is a test
Wait := True
SetTimer WaitToClose, 100
While Wait
	Sleep 100
Sleep 100
Send ^aPrevious text erased !

Return

WaitToClose:
	IfWinActive , , Do you want to save the changes?
		ControlClick Button2, , Do you want to save the changes?
	IfWinExist Save As
		other := True
	IfWinExist Open
		blah := True
	If other And !WinExist("Save As")
		otherClosed := True
	If blah And !WinExist("Open")
		blahClose := True
	If (otherClosed And blahClose)
		Wait := False
	If !Wait
		SetTimer WaitToClose, Off
Return

1. Run the script.
2. Run Notepad
3. It should send some text.
4. Open the "Save As" menu and close it (doesn't save it's useless).
5. Open the "Open" menu (the button "No" will automaticaly be clicked, soemtime it seems the window is frozen, it's ok and should continue after some times it's because of the use of timer and no pause between actions).
5. The text should be changed.

4 and 5 can be inverted (Open first then Save As).