Jump to content

two different loops in same script


Recommended Posts

Hello,

i inted to make a script with Send(keys) that loop, entire loop takes around 25 seconds, is possible to insert in same script another loop that takes 20 min for example to send another keys every 20 min?

Global $Paused
HotKeySet( "{F7}", "_TogglePause" )

Func _TogglePause()
$Paused = Not $Paused
While Not $Paused
Sleep( 250 )
ToolTip( 'Script is "Paused', 0, 0 )
WEnd
ToolTip( "" )
EndFunc
    While 1
            If $Paused Then
    Send('{TAB down}')
    Sleep(500)
    Send('{TAB up}')
    Sleep(100)
    Send('{2 down}')
    Sleep(3000)
    Send('{2 up}')
    Sleep(500)
    Send('{2 down}')
    Sleep(3000)
    Send('{2 up}')
    Sleep(500)
    Send('{2 down}')
    Sleep(3000)
    Send('{2 up}')
    Sleep(500)
    Send('{2 down}')
    Sleep(3000)
    Send('{2 up}')
    Sleep(500)
    Send('{2 down}')
    Sleep(3000)
    Send('{2 up}')
    Sleep(500)
    Send('{2 down}')
    Sleep(3000)
    Send('{2 up}')
    Sleep(4000)
EndIf
wend

Thanks in advance, have a nice day.

Link to comment
Share on other sites

instead of using sleep, you could start 2 different timers (timerinit) then in the same loop, check the timerdiff of both timers and if 1 is 25 seconds, run the 1st function and reset the timer 1

if the other is 20 min, run the 2nd function then reset timer 2

$timer1 = timerinit()

$timer2 = timerinit()

while 1

if timerdiff($timer1) = 25000 then

do first thing

$timer1 = timerinit()

endif

if timerdiff($timer2) = 1200000 then

do other thing

$timer2 = timerinit()

endif

wend

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Hello,

There's a couple of problems with above, it will make your computer hot, and if anything is a little busy or delayed the times won't match exactly, it will miss the action.

Try this.

$x = 0
While 1
    If Mod($x, 5)  = 0 Then ; 25 seconds
        ; do first thing
    EndIf

    If Mod($x, 240)  = 0 Then  ; 20 mins
        ; do second thing
    EndIf

    Sleep(5000)
    $x += 1
WEnd

It's not absolutely accurate because the time taken to do the things will delay the loop. If you want to avoid this slippage, trim the 5000 based on the actual time.

Richard.

Edited by RichardL
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...