gzd Posted October 2, 2007 Share Posted October 2, 2007 Hi, Taking forward the basic demo from user guide about Notpad Window WinWaitActive: Run("notepad.exe") WinWaitActive("Untitled - Notepad") .... How do i make the WinWaitActive to run in a loop until i choose to terminate it? For example, making it trace all specific windows (like notepad) coming untill closing and application X button as below. #include <GUIConstants.au3> GUICreate("Window Title", 200, 100) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 2, 2007 Share Posted October 2, 2007 (edited) Pretend, just for a moment, that we CAN'T read your mind, and try that question again... what do want the loop to do with WinWaitActive? Edited October 2, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
aslani Posted October 2, 2007 Share Posted October 2, 2007 As far as I know, WinWaitActive() is already a loop of Do...Until. Do -Nothing- Until "Notepad.exe" is active [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
gzd Posted October 2, 2007 Author Share Posted October 2, 2007 Pretend, just for a moment, that we CAN'T read your mind, and try that question again... what do want the loop to do with WinWaitActive? I want to create a basic gui that waits for specific window to appear and press a button there.The written above shows how to do it once. But I want it to re-wait for next time the window appears (in a loop) untill i decide to terminate the application with the "x" button Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 2, 2007 Share Posted October 2, 2007 I want to create a basic gui that waits for specific window to appear and press a button there. The written above shows how to do it once. But I want it to re-wait for next time the window appears (in a loop) untill i decide to terminate the application with the "x" button Perhaps like this: #include <GUIConstants.au3> Opt("GuiOnEventMode", 1) GUICreate("Window Title", 200, 100) GuiSetOnEvent($GUI_EVENT_CLOSE, "_Quit") GUISetState(@SW_SHOW) While 1 If WinActive($WinTitle) Then ; Wait for active Send("Whatever") ; Send stuff once Do Sleep(20) Until Not WinActive($WinTitle) ; Wait for NOT active EndIf WEnd Func _Quit() Exit EndFunc You'll have to fill in what you want for $WinTitle Note the GUI is in event mode so you don't have to worry about keeping a GuiGetMsg loop going. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
gzd Posted October 2, 2007 Author Share Posted October 2, 2007 Perhaps like this: #include <GUIConstants.au3> Opt("GuiOnEventMode", 1) GUICreate("Window Title", 200, 100) GuiSetOnEvent($GUI_EVENT_CLOSE, "_Quit") GUISetState(@SW_SHOW) While 1 If WinActive($WinTitle) Then ; Wait for active Send("Whatever") ; Send stuff once Do Sleep(20) Until Not WinActive($WinTitle) ; Wait for NOT active EndIf WEnd Func _Quit() Exit EndFunc You'll have to fill in what you want for $WinTitle Note the GUI is in event mode so you don't have to worry about keeping a GuiGetMsg loop going. It works, Thanks There is one problem though, it takes 50% CPU with that implementation Any suggestion? Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 2, 2007 Share Posted October 2, 2007 It works, Thanks There is one problem though, it takes 50% CPU with that implementation Any suggestion? Yeah, there's a Sleep(20) that keeps the Do/Until loop from doing that, but not in the While/WEnd loop. Just add the Sleep: While 1 If WinActive($WinTitle) Then ; Wait for active Send("Whatever") ; Send stuff once Do Sleep(20) Until Not WinActive($WinTitle) ; Wait for NOT active EndIf Sleep(20) ; <--- add sleep here WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
gzd Posted October 2, 2007 Author Share Posted October 2, 2007 Yeah, there's a Sleep(20) that keeps the Do/Until loop from doing that, but not in the While/WEnd loop. Just add the Sleep: While 1 If WinActive($WinTitle) Then ; Wait for active Send("Whatever") ; Send stuff once Do Sleep(20) Until Not WinActive($WinTitle) ; Wait for NOT active EndIf Sleep(20) ; <--- add sleep here WEnd Perfect!!! Thanks a lot Link to comment Share on other sites More sharing options...
gzd Posted October 9, 2007 Author Share Posted October 9, 2007 It looks like this option works better: While 1 If WinExists($WinTitle) Then WinActivate($WinTitle) Send("Whatever") ; Send stuff once EndIf Sleep(20) ; <--- add sleep here WEnd Problem: If operated from a server, script doesn't work while I'm disconnected. Any idea? Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 9, 2007 Share Posted October 9, 2007 Problem: If operated from a server, script doesn't work while I'm disconnected.Any idea?No idea what you are talking about... what does "operated from a server" mean? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
gzd Posted October 9, 2007 Author Share Posted October 9, 2007 I have added to your example above a button press, but when running the script the button doesn't want to be pressed... (although it gets the focus correctly). Strangely, when i move manualy the foucs from the popup to other applications in windows toolbar it works. I'm working on WTS server with remote desktop but i don't think it's the problem anymore. Also, i have tried to replace the Control click with - send ("{ENTER}") but it didn't help. While 1 If WinActive("Window Name") Then ControlFocus ("Window Name", "Button Name", ID) sleep(20) ControlClick("Window Name", "", ID) Do Sleep(20) Until Not WinActive($WinTitle) End If Sleep(20) Wend Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now