I have 2 shortcuts (F1 and F2) which i would like to toggle each time i hit a button on my mouse (using steer mouse to trigger KM macros)
Right now I am only able to assign both F1 and F2 to different buttons, but i bet there is a way to have a macro toggle between triggering the F1 and F2 keys.
If I understand correctly, you have two macros, one on F1 and the other on F2. You press a button on your mouse, and the first time you hit it, you want it to run F1. The next time, F2, then back to F1 on the next click, right?
You could use a global variable and a controller macro:
Controller Macro:
if NextMacroToRun = "F1" or if NextMacroToRun is empty
execute macro F1
set NextMacroToRun to "F2"
else
execute macro F2
set NextMacroToRun to "F1"
end if
Set your mouse to trigger the controller macro, and it should alternate between running F1 and F2. There are probably many other ways of doing this; this is just the first one I thought of, so I have no idea if it's the simplest, best, etc. But it should work :).
(EDIT: uncheck the "Display Toggle" flags in the actions above.)
Both Macro Groups, Group1 and Group2, would have their own copies of the same macros with opposite triggers (F2, F1).
Of course, having duplicate macros is rarely a good idea, in case you need to edit the macros (now twice) but I wanted to share this approach anyway. The one thing it has going for it is that it will be fast, because there's no level of indirection added at runtime.
A sharp observer may notice that there's a very slim chance of a user pressing a key while both (or neither) groups are enabled. That can be partially solved by adding a Lock Semaphore action to the start of each macro, including the Toggle macro above. There is a better solution which I can explain if asked.
Due to the duplication required, I think this solution is only the best one when speed is ultra-important, like playing a competitive online game.
Also, noisneil thank you for spelling it out for me - I worked from your screenshot. I am so reliant on my KM macros and streamdeck, but rarely get into the details or iterate much, so this really helped.
I'm glad you have it resolved, but just a note on this:
Try to be a little careful with the terminology. In Keyboard Maestro, triggering is going to have people thinking of Triggers, things that start a macro, but you are talking about actions, specifically the Type a Keystroke action. So better to ask “between typing (or simulating) the F1 and F2 keys”.
Read the Quick Start to get a handle on the terminology (and maybe the Glossary) and it will make it a lot easier to get your question across.