Good afternoon all,
About a year ago I had help here in creating a macro, the aim is that when I press 1 it keeps spamming 1 every second until I release the key.
I have the following from back then but it simply doesnt work, any suggestions from you macro ninja's would be great?
Do other macros still work?
Thanks for coming back, this is the only macro I am trying to use right now.
Any chance you could see if any of the default macros work? I'm trying to determine if something is going buggy with your installation of Keyboard Maestro, or if it is macro or action specific. Thanks
That trigger wont work properly for “down” because the action of simulating the "1" keystroke involves releasing the "1", pressing the "1", and the act of releasing the "1" will stop the hot key from being down.
The hot key should be just the "1 is pressed".
But ignoring that, it should work since the Until action should continue while the "1" is pressed, and the test tests the keyboard state which should be correct.
However that said, the behaviour of simulating a keystroke which is itself a hot key trigger has never been well behaved. The Type a Keystroke: 1 may or may not trigger the macro, and if it does then the key will be swallowed by the hot key API and another instance of the macro will be started which could lead to weird behaviour.
So you probably should start the macro with a Set Macro Disabled action to disable the macro, and then finish the macro with another action to enable the macro.
I usually ask the questions, but today I thought I'd try to answer this one. I think I have four alternatives for you, and possibly one of them will work for you.
(You probably already know this, but in case you didn't...) I will say that you can get this result without Keyboard Maestro by setting the Key Repeat bar (and the Delay until Repeat bar) in the Keyboard section of System Preferences. You will probably say that you don't want that, so I'll suggest some more ways. But it does exactly what you specified.
A second way is to change your methodology a little bit. Instead of holding it down to start and release to stop, you can create a macro that will let you press it once to start and a second time to stop it. That should get you the same result and actually be easier on your finger. If you like this idea, I may help you write such a macro, but I suspect you can solve this one yourself. If I were writing this I would also have one sound effect play when it's turned on, and a different sound when it's turned off. Probably TINK/POP which sound like ON/OFF to me.
A third way is, rather than have a trigger detecting if the 1 key is pressed, just have a macro running continuously and have it check of the key is down. (A single macro can even work with multiple shortcuts.) This macro can use pause statements or other mechanisms to ensure that the desired result occurs at the frequency you want. If you need help writing this, let me know, it's not too hard. If you include PAUSE statements then this solution isn't as CPU-heavy as it sounds.
A fourth way works as follows. Read this idea right to the end before you reject it. In some ways it's the best idea. Simply write a macro that uses a periodic trigger that triggers every 1 second (which is the minimum trigger rate) and create an IF statement that determines if the key is down. In your code it looks like you want it spammed more often than that. You can achieve that by having this macro press the key not once, but 4 or 5 times over 0.9 seconds. That will give you the frequency you want. It has the side effect of lasting a little bit beyond the time you release the key. but if you're spamming I doubt that small error will bother you.
I don't know exactly what you are doing, but my hunch is that the last idea will really work well for your needs. It meets most of your stated requirements really well. But if you indicate exactly what you're doing there may be an even better solution. For example, I think I found a piece of really tiny UNIX/macOS utility years ago that spams a key, and you can probably run this utility from a KM macro, triggered by the typing of the key.
Hmm, the fourth solution doesn't have the delay problem if the IF statement is within the 4x loop. I was thinking the IF statement was outside the loop, but it can be written the other way.