Sign in to follow this  
Followers 0
TuMiM

Loop with sleep

8 posts in this topic

I am not sure if this is even possible but i have a tray script that is supposed to wait for an application to be active and then run a control S and then wait a specific amount of time to run control S again. The intention was that if another windows of the same program was open it would immediately run a control S again but i don't think that's possible. I also want the wndsync process to run every five minutes at the same time. The biggest problem is that while it is sleeping, it won't respond to the menuitem clicks. Is there a way around this? Thanks

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Delay = IniRead(@ScriptDir & "\LogLaunch.ini", "Global", "Autosave", "")
$RepSet = IniRead(@ScriptDir & "\LogLaunch.ini", "Global", "RepSet", "")

Opt("WinTitleMatchMode", 2)
Opt("TrayMenuMode",1)
;$menurep = TrayCreateMenu("Replicate")
;$menuitemAuto = TrayCreateItem("Autosave",$menuWeb)

TrayCreateItem("")
$menuitemRep = TrayCreateItem("Replicate")
$menuitemExit = TrayCreateItem("Exit")

TraySetState()
While 1
    $tMsg = TrayGetMsg()
    If ProcessExists("wndsync.exe") Then
    Else    
    Runwait(@ScriptDir & "\wndsync.exe " & $RepSet)
    Endif
    If WinActive("- Microsoft Office Document Imaging") Then
    Send("^s")
    Sleep($Delay)   
    Send("^s")
endif

    Select
        Case $tMsg = $menuitemExit
            Exit
        Case $tMsg = $menuitemrep
            Run(@ScriptDir & "\wndsync.exe " & $RepSet)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



On event mode might be able to get around this problem. To see if there are two of the same processes active, use _Singleton. Everything else in your code seems to be in place.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Also the AdLib functions: AdLibEnable() in the production version, or AdLibRegister() in the Beta.

:)


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

Hi,

If you wait for certain windows to active... why not just use WinActive?

While 1
    If WinActive("Untitled ") Then
        MsgBox(0,"","Hi Mr. Untitled")
        Exit
    EndIf
WEnd

Hi ;)

Share this post


Link to post
Share on other sites

Hi,

If you wait for certain windows to active... why not just use WinActive?

While 1
    If WinActive("Untitled ") Then
        MsgBox(0,"","Hi Mr. Untitled")
        Exit
    EndIf
WEnd

I am doing that, problem is that there is a sleep command after that which makes it wait and does nothing until that sleep command is finished. The active windows is always the same program but could be a million different files that it may have open. So if i current window is active, witout the sleep command, it will constantlly run the control S which will make it impossible for the user.

Share this post


Link to post
Share on other sites

On event mode might be able to get around this problem. To see if there are two of the same processes active, use _Singleton. Everything else in your code seems to be in place.

I am not sure how guionevent would help. Guionevent would work even if its running the sleep command?

Share this post


Link to post
Share on other sites

I am not sure how guionevent would help. Guionevent would work even if its running the sleep command?

Yes, a GUI control event or an AdLib will interrupt a Sleep().

:)


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

If you don't want to use adlib as Psalty suggested, you may want try this:

; time delays using Timer

$a = TimerInit()
While 1
    If TimerDiff($a) > 2000 And WinActive("Untitled ") Then ; checks every two seconds to see if Untitled window is active
        Send("^{s}") 
        $a = TimerInit()
    EndIf
    If WinActive("Untitled ") Then Send("") ; Continuously checks if Untitled window is active
WEnd

Hi ;)

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