In the script included below I try to run a chain of commands. But when run by pressing F1 the command will run both SendAndLoopFor() invocations immediately after each other without waiting for the inner loop to complete.
I tried to 'force' this await by adding a return "" inside the function, and assigning a variable with it instead Foo := SendAndLoopFor() but even then it would not await the operation.
Is there a way to await the completion of the SendAndLoopFor() command before executing the next?
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#MaxThreadsPerHotkey 13
#SingleInstance
F1::
Done = 0
Toggle := !Toggle
Loop
{
If (!Toggle)
Break
SendAndLoopFor("4", -13600)
SendAndLoopFor("5", -13600)
}
return
SendAndLoopFor(TSend="", Timeout=0)
{
Send %TSend%
SetTimer, LoopLimit, %Timeout%
Loop
{
If(!Toggle)
Break
If(done == 1)
{
done = 0
Break
}
MouseClick, left
sleep 83
}
}
LoopLimit:
Done = 1
Return
SendAndLoopForloop has aSleeptime of only 83 milliseconds. Is this intentional? Because your current delay will be almost imperceptible. - David Metcalfe