Jump to content

How to manage delays more efficiently? WinWait, Sleep? Something else?


Recommended Posts

I'm starting to be able to create short scripts, but the execution is erratic, some pop ups and sounds show up to quick or to slow.

I have set some win wait and sleeps but still I can't seem to get a good flow between steps, any suggestions welcome. This happens with this example:

;WinSetState("[CLASS:SciTEWindow]", "", @SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
If WinExists ("Mozilla") Then
MsgBox(0, "", "Firefox is now running")
Sleep(1000)
Else
MsgBox(0, "", "Please Start Firefox")
EndIf
WinWaitActive("Mozilla")
If WinExists ("Mozilla") Then
MsgBox(0, "", "Firefox is now running")
Sleep(1000)
Else
MsgBox(0, "", "Please Start Firefox")
EndIf

PS. Do I need to repeat my Opt("WinTitleMatchMode", 2) before EVERY Window or just leave it at the beginning of the script?

Thanks

Link to comment
Share on other sites

Not quite sure what the problem could be, I haven't played much with handling windows, but this would be how I would probably start.

HotKeySet("{ESC}","Escape")
Global $FFClass = "[CLASS:MozillaWindowClass]"

While Not WinExists($FFClass)
    Switch MsgBox(16+5+262144, "Error!", "Please Start Firefox.")
        Case 4
            ContinueLoop
        Case 2
            Escape()
    EndSwitch
WEnd

If WinExists($FFClass) Then
    WinActivate($FFClass)
    MsgBox(64, "Info!", "here's where you can do stuff with FF")
Else
    MsgBox(16,"","")
EndIf

Func Escape()
    Exit
EndFunc

P.S. To get the "CLASS" name of windows, use the "AU3Info" tool under the tools menu in the SciTE editor.

Edited by ApudAngelorum
Link to comment
Share on other sites

Thank you Apud,

Actually your script is much better than mine!

But still on my machine, the Windows Chime sound comes before the pop up, how can I make sure everything is in synch everytime?

Sometimes it works, and sometimes not, depending on what windows are open ect...

For example:

The sound comes first

Then maybe half second later the pop up:

MsgBox(64, "Info!", "here's where you can do stuff with FF")

I hope I'm being clear!

Edited by xuzo
Link to comment
Share on other sites

Actually that might just be it, I just installed Ad-Aware yesterday, causing all kinds of slow downs and crashes.. will add exeption or switch to any anther anti virus program.

P.S. To get the "CLASS" name of windows, use the "AU3Info" tool under the tools menu in the SciTE editor.

Problem with that is browser backwards compatibility, for example:

Firefox 2.0

MozillaUIWindowClass

Firefox 12.0

MozillaWindowClass

Can I use operators 1,2,3 and 4 for Windows Class as I do for titles to be compatible with more broswers? Like these?:

Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Edited by xuzo
Link to comment
Share on other sites

Actually that might just be it, I just installed Ad-Aware yesterday, causing all kinds of slow downs and crashes.. will add exeption or switch to any anther anti virus program.

Problem with that is browser backwards compatibility, for example:

Firefox 2.0

MozillaUIWindowClass

Firefox 12.0

MozillaWindowClass

Can I use operators 1,2,3 and 4 for Windows Class as I do for titles to be compatible with more broswers? Like these?:

Nope.

If you want backwards compatibility, I recommend you do it the way you were with option 2 for the opt statement.

Link to comment
Share on other sites

Dont know if this will help

I use this when im waiting for windows to popup form an action all the info i get from the info finder

Opt("WinTitleMatchMode", 2) ;=> Matchs a string with in the title (ie Google - Mozilla Firefox)

Opt("WinTextMatchMode", 2) ;=> Matchs a string with in the Text

Func _WinWaitActivate($vWintitle, $vWinText, $timeout)

WinWait($vWintitle, $vWinText, $timeout)

If Not WinActive($vWintitle, $vWinText) Then WinActivate($vWintitle, $vWinText)

WinWaitActive($vWintitle, $vWinText, $timeout)

EndFunc ;==>_WinWaitActivate

$timeout = 3 ;=> acts as a sleep using whole numbers, 3 second wait if the window doesnot show up will continue script 0 is unlimited

$vWintitle = "Mozilla Firefox" ;=> title of the window

$vWinText = ""

$Controlid = "Button1"

_WinWaitActivate($vWintitle, $vWinText, $timeout) ;=> will wait for the window to showup and then activate that window ready for you action in this case click a button

Controlclick($vWintitle,$vWinText,$controlid)

_WinWaitActivate($vWintitle, $vWinText, $timeout) <<< this will not work if your computer is locked

Edited by GNGNUT
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...