Sign in to follow this  
Followers 0
Sparrowlord

Confused o.O

4 posts in this topic

What I'm trying to do is this.

#1. Search for a window named "Hey" but only search for that window once every five minutes.

#2. Then after an hour close a window named "Main" and reload it.

But I got caught up with the timers, heres what I'm thinking of:

$5minutetimer = TimerInit()
$1hourtimer = TimerInit()

While 1

    $5minutediff = TimerDiff($5minutetimer)
    $1hourdiff = TimerDiff($1hourtimer)

    If $5minutediff > 300000 Then
        If WinExists("Hey") Then
            WinActivate("Hey")
            ControlClick("Hey", "", "Button1")
            $5minutetimer = TimerInit()
        EndIf
    EndIf

    If $1hourdiff > 3600000 Then
        WinClose("Main")
        WinWaitClose("Main")
        Sleep("10000")
        Run($path)
        $1hourtimer = TimerInit()
    EndIf
    
WEnd

Now I have 2 questions.

#1. Will this cause a heavy load on my pc looking for those windows?

#2. Will the above code work? I just typed it now by hand and I don't have the time to run/check it, speaking of that im heading off to work now ><

I would appreciate any help :)

Thanks,

Spar

Share this post


Link to post
Share on other sites



toss in a sleep ( 10 ) somewhere in the loop outside of the if statements.

I would change the TimerDiff($5minutetimer) and TimerDiff($1hourtimer) references to Integers instead of leaving them as floating point integers.

But yea, without a sleep statement in the loop it will go crazy on your computer.

The code should work by the looks of it, provided $path is defined properly.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

What I'm trying to do is this.

#1. Search for a window named "Hey" but only search for that window once every five minutes.

#2. Then after an hour close a window named "Main" and reload it.

; ...

Now I have 2 questions.

#1. Will this cause a heavy load on my pc looking for those windows?

#2. Will the above code work? I just typed it now by hand and I don't have the time to run/check it, speaking of that im heading off to work now ><

I would appreciate any help :)

Thanks,

Spar

Just a sleep(100) to let the CPU get away from your script's loop for a while, as Tobei said.

The reset of the 5min timer needed to be outside of the If/EndIf for "Hey".

I also removed unnecessary saving of the TimerDiff() to a variable, but that's personal just preference:

$5minutetimer = TimerInit()
$1hourtimer = TimerInit()

While 1
    If TimerDiff($5minutetimer) > (5 * 60 * 1000) Then
        If WinExists("Hey") Then
            WinActivate("Hey")
            ControlClick("Hey", "", "Button1")
        EndIf
        $5minutetimer = TimerInit()
    EndIf
    If TimerDiff($1hourtimer) > (60 * 60 * 1000) Then
        WinClose("Main")
        WinWaitClose("Main")
        Sleep("10000")
        Run($path)
        $1hourtimer = TimerInit()
    EndIf
    Sleep(100)
WEnd

:P


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

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