I am trying to make a macro that, while I’m playing a game, will press a button once a second. I have set up a macro that should do this, but for some reason, it won’t work. Here are the steps of my current macro:
Triggered by hot key F9
Repeat Actions 9999 Times
Press button "="
Pause for 1 seconds
Could someone tell me what I am doing wrong?
It’s wrong to use a macro to cheat (sorry, couldn’t resist
).
It’s not easy to answer with so little information, but there are several reasons why it might not work:
- the macro is not enabled when you want to use it;
- the game intercepts the F9 key.
- the button you want to press is not a standard OS X button, so KM’s “Press a Button” action doesn’t “see” it;
You can test against 1 and 2 at once, for example by adding a “Play Sound”, “System Beep” or “Speak Text” action at the top of your macro. If you don’t hear it when you attempt to trigger the macro, then the macro isn’t triggered. In this case, start by making sure the macro is in a group enabled when the game is at the front, make that group temporarily global (enabled in all applications), or temporarily move the macro into an existing global group, then try again.
If you still can’t hear the first action, then the game probably intercepts the F9 key for its own use. Try with a different hot key, or if the game allows you to access the menu bar, try to give the macro the Status Menu trigger, and try to run it from the menu.
Now the third case is more tricky. First, instead of trying to press the button repeatedly, start by trying to press it once. When you’ll get that working, then only add the repetition. Because if the macro is triggered and you didn’t check the “Stop macro if button cannot be pressed”, an occurrence of the macro will keep running in the background for 9999 seconds each time you trigger it!
Once you removed the repetition for now, make sure that “Stop macro if button cannot be pressed” checkbox is checked. Then add another “Play Sound” or even better “Speak Text ‘the button was found’” at the bottom of the macro. If you can’t hear it when you trigger the macro, it means the button couldn’t be found and things become very difficult (or even impossible). Because that button is not a standard one and KM doesn’t see it. In this case, I think the only way left would be to use a Click action, either by clicking at given coordinates if the button is always at the same place, or relative to a found image (click the menu next to “relative to the” to see the different possibilities).
1 Like
BTW, I meant to say this, then forgot:
Instead of repeating the action 9999 times, you should use a “Until” action, and set it to repeat until a given key is down. This way you can stop the macro at any point.
1 Like
Even better would likely be “repeat until target application is not at the front”. That way the macro will stop when you leave the application.
You may also want to start the macro with a Cancel Other Macros action so that if you trigger this macro a second time, it will cancel the first instance.
And don’t be overly afraid of the click at found image action - it is actually a very reasonable solution. To click relative to an image, you use the Mouse Click action, configure it to be relative to a found image, and take a screenshot of the desired area of the screen using Command-Control-Shift-4, and paste it into the image well on the action. The image has to be unique (which includes not being visible in the action if the image is small enough not to be shrunk in the image well) otherwise Keyboard Maestro will not know where to click. The Display option in the action will allow you to see where Keyboard Maestro is matching.