Help having macro alternate 2 different key commands

Hi,

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.

I am on Mac studio, Ventura, Pro Tools 2023.9

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 :).

-rob.

1 Like

Thanks so much - let me be more clear sorry about that:

In pro tools, F1 is slip mode, and F2 is shuffle mode.

I simply would like a macro that switches between triggering the F1 key and F2 key.

Does that change the solution at all?

Thanks so much!!

I saw you were writing a response so I waited for it before responding.

I was also thinking of a macro that toggles the two function keys by doing this: (using some SteerMouse trigger, whatever that is)

(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.

Oh, then that can probably all be done in one macro:

if NextUse = "F1" or if NextUse is empty
  send keystroke "F1"
  set NextUse to "F2"
else
  send keystroke "F2"
  set NextUse to "F1"
end if

That would send F1 the first time you clicked the button, then F2, then F1, etc. Is that what you want?

-rob.

2 Likes

I would do it exactly how @griffman described:

3 Likes

Oh, maybe that's what he meant. I interpreted him differently, so my answer is solving a different problem.

It works perfectly - Thank you guys SO MUCH!

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.

You guys made my day, thank you!

1 Like

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.

4 Likes

Copy that Peter. Thanks again for the support- you rock!

1 Like