0
votes

happy new year 2021, I'm new to AHK, I'm trying to get the script, to send text to a window, there are 2 different time intervals I want.

first loop must send a word every 14.5 seconds second loop must send three words (each one followed by the enter key) every 30.5 seconds.

this is what I have.

#SingleInstance Force

F7::
Toggle := !Toggle
SetTimer, Loop1, % (Toggle) ? 14500 : "Off"
SetTimer, Loop2, % (Toggle) ? 300500 : "Off"
return

F5::Reload

Loop1:
SendInput .word1{Enter}
return

Loop2:
SendInput .word2{Enter}
SendInput .word3{Enter}
SendInput .word4{Enter}
return

What I want for the script is that if I hit F7, it starts, and both loops execute at once, sending the 4 words to the active window, and then well each loop waits its respective time delay and repeat until I either press F7 again F5 to reload or stop it altogether.

the issue is, it is NOT doing it as expected, it actually waits the "timers" first then executes, how can I make it so as soon as I hit F7, it sends the 4 words followed by enter, THEN starts the timers?

I even tried using SetTimer ....... ? 0 .......

but it runs once, then never again.

any help would be greatly appreciated.

cheers

JL

1

1 Answers

1
votes

Why not call a gosub before starting the timer?

#SingleInstance Force

F7::
Toggle := !Toggle
if(Toggle){
    gosub Loop1
    gosub Loop2
}
SetTimer, Loop1, % (Toggle) ? 14500 : "Off"
SetTimer, Loop2, % (Toggle) ? 300500 : "Off"
return

F5::Reload

Loop1:
SendInput .word1{Enter}
return

Loop2:
SendInput .word2{Enter}
SendInput .word3{Enter}
SendInput .word4{Enter}
return