How to organize key sends and prevent overlap?

TLDR: The second send key in my if statement is slower than the first one, and I have no idea why, but it’s messing up my program’s timing. any suggestions?

So, I am trying to get Keyboard Maestro to automate testing of a game for me. It needs to go up and down over and over again (this can be accomplished by pressing the w and s keys). Currently, it works (kind of), but ends up breaking down after around twenty minutes. I did some testing, and this is because instead of sending wwwwwwwwwwww then ssssssssssssssss, it starts sending swswswswswswswsws or some corrupted mix of the two that prevents the character from moving normally.

Currently, my code is organized so that every 120 seconds, it sends 5,000 “press and repeat strokes” of w, then changes a variable so after the next 120 seconds it sends 5,000 “press and repeat strokes” of s (and so on and so forth). Somehow, they’re starting to overlap after a while… and I’m not sure why. If anyone could help that would be great. Of course, there are probably many issues with my setup too.

Is there anyway to make it send keys for a certain amount of time rather than a number of them?

Is there any way to just run a macro without setting weird intervals?

My ideal code is one where there is no trigger… no weird intervals… it just starts and then runs indefinitely (like in a while True loop). Each time it runs through the loop, it alternates between sending the “s” and “w” keys (I have this figured out) and it sends them for a certain amount of time, not a number of key sends (is this even possible?). And most importantly, there is no overlap (maybe sending them for a certain number of time will fix this).

Thanks so much :slight_smile:

*update: I did some testing, and it appears to be completely random. It starts off and takes about 51 seconds, then the second round takes about 2.5 minutes, then everything’s messed up :|*strong text

I’m afraid I have no idea what you are doing.

If you “send 5,000 “press and repeat strokes” of w” I don’t even know what that means. If you press and hold, then you can’t send 5000 of them. By definition you cannot press and hold multiple times.

If you send large numbers of keystrokes, they will go into a queue, both within Keyboard Maestro and within the system. The time it takes to process will be variable and depend what else is in the queue.

OK, I posted about this earlier when I was still trying to figure things out, but now I’m pretty sure it’s a bug.

I have an action that runs every 5 minutes, and each time it runs it presses and repeats a key (alternating between “w” and “s”). The first time, this is accomplished in 1 minute 45 seconds. The second time, it is accomplished in 2 minutes 49 seconds, and the third time it takes 3 minutes and eight seconds. As you can see, it is slowly getting worse.

Why is this a problem? Well, it eventually gets so slow that the actions start overlapping, and the result is a jumble of the two. So far, I have yet to come up with a workaround, but I will post back if I do. I don’t want to use a variable to keep pushing back the time, because it could go on for hours…

Everything is working now (I guess). It will type 5,000 “w”'s, and then 5,000 “s”'s, and so on, but the lag gets outrageous. Is the performance really that bad? Or am I setting something up wrong?

I have moved this back here. I’m pretty sure what you are describing as a bug is simply not understanding what is going on, or trying to do things in an unsupported manner, so first lets figure out what you are doing and what you are expecting, and then we can figure out why it is not working as you expect.