Why do you do two loops of repeated w presses followed by repeated s presses? There may be a very good reason for it such as your program needs multiple key presses, but doing the loops that way won't ensure accuracy for 3 seconds.
I would recommend this as your first step for holding w down for 3 seconds, waiting 2 seconds, and then holding s down for 3 seconds.
Code: Select all
F1::
Send {w down}
Sleep 3000
Send {w up}
Sleep 2000
Send {s down}
Sleep 3000
Send {s up}
return
If you would like the whole thing to keep repeating, you can put a Loop block all around it like you did in your original code. In fact, if you want to keep using your original code and have the whole sequence repeat, you can put a Loop inside of a Loop.
However, if the above code does not work, you may need to do repeated keystrokes like you're doing in your original code. I wouldn't bother using two lines to send one key like you're doing, since you can just use
Send w and
Send s to do the same thing. However, here's a suggestion for doing a loop for a certain amount of time:
Code: Select all
F1::
Loop
{
starting_time:=A_TickCount
While (A_TickCount-starting_time<3000)
Send w ; the { and } on the line above and below this line are optional
Sleep 2000
starting_time:=A_TickCount
While (A_TickCount-starting_time<3000)
Send s
Sleep 2000
}
return
First thing I added was a custom variable called starting_time that copied the value of the built-in
variable A_TickCount. The While loop evaluates an expression every time it is about to run. The expression in this case is is the new value of A_TickCount (which is updated every 15ms or however fast; maybe it's always accurate when the variable is called) 3000 units (milliseconds) larger than the value starting_time has? If it is smaller than 3000 ms difference, then it'll send the w key. Otherwise it will break the loop and move onto the next step which is Sleep 2000. Take note that A_TickCount is being dynamic and always changing, while starting_time is static and will stay at whatever value it was set at -- until it is changed again as per line 8 in the code above.
Check out
https://autohotkey.com/boards/viewtopic.php?f=7&t=11952 for ways to control your loop so you can stop it when you want.