Autopress spam key


Please I need your help for the following macro:
I would like to press one time F and start spamming 0 until I press again F.
I was able to create a macro that spam 0 if I hold F, but I can't find an option for starting the macro with just one time press of F and stop again pressing F.

I don't think there's an "option" for doing that, but it certainly can be done with a little bit of code.

What I would do is:

  1. Write one macro with a hotkey of F that flips a global variable from 1 to 0 each time you press the key;
  2. Write another macro that runs continuously and presses the zero key if that global variable is a 1.

If that's insufficient advice, I can probably write the code after my breakfast.

Okay here's the first of the two macros you require. Since this is one of the shortest macros in KM history, I'll just post a screenshot because it would take more work for you to upload it than to simply type it in:

The macro won't work until you first assign a value of zero to the SpamZero variable. If you don't know how to assign a variable a value, I can explain it.

The second macro is this:

That's the minimum that you require. But there are ways to improve this. Firstly, I would start the Zero macro with a periodic timer of 1 second (and insert a Semaphore Lock with a 1/100 second failure condition) so that the Zero macro is always running, even if you cancel all macros. Secondly, I would probably add a condition to the group that these two macros are in so that they run only when a certain app is running, but you didn't say which app you were running. (I don't need to know, but it sounds like a game.)

1 Like


Thanks a lot, the script above helped a lot.
I will try your suggestions.

You are very welcome.

Keep in mind, I gave you code to implement your specifications. Personally, I don't think your approach is the best approach. But everyone has to learn from experience what the best approach is.