Jump to content

Loop with sleep


TuMiM
 Share

Recommended Posts

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
Link to comment
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.
Link to comment
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?

Link to comment
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
Link to comment
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 ;)

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...