Sign in to follow this  
Followers 0
gzd

Repeating Window handle

11 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0