TOGGLE possibility?

Hello all. As a newbie user who’s looked around a bit, I’m wondering if it’s possible to set up a macro that toggles between certain keys. For example, I want to set up a macro that toggles between hitting F1 and F2 every time I hit one mouse button. Is that doable?


Hi Eric,

This is definitely doable. Here's one way you might go about it:

Toggle F1:F2.kmmacros (2.9 KB)

The key to alternating between possible states like this is to set a variable to the toggle's status every time the macro is triggered, then check that variable the next time the macro is run so it knows which state to toggle to next. The action I used for that check is a Switch/Case, which I think is easier to understand and more specific for branching variable states like the one used here, but you could accomplish a similar setup with an If Then Else action as well.

If you have any further questions, feel free to ask!


Cool, thanks! I’ll give it a whirl. Greatly appreciated.

Alhough, if I may stupidly ask…how do I implement the file you included?

No worries! We all have to start somewhere :slightly_smiling_face:
Just opening it like you would any other file should automatically import it into KM. Please note that both it and the macro group that contains it will be disabled by default, so you’ll need to make sure the macro is itself enabled and is placed in an enabled group before it will work.

1 Like

All right, I got it in there, made sure it was enabled, and put it in the folder for the app I want to use it with. Alas, it's not working. Anything you see that might be a culprit?

Whoops! Sorry about that; this was my mistake, not yours. The problem is that the macro had no initial value for the variable it relies on, so neither the F1 or F2 options applied, and thus nothing would happen when the macro was run. Here's a revised version that initializes the variable by setting it to F1 if the variable is empty or doesn't exist, which should fix the issue:

Toggle F1:F2.kmmacros (3.7 KB)

Alternatively, you could set the variable to either F1 or F2 through the Variables pane in KM's preferences:

Sweet! That did it! Thanks again for your help. One of these days I’ll study this and learn the logic behind it. But for now, I’m just happy that it works. Cheers!

1 Like