I have a set of 9 macros that use F1-F9 as triggers.
When I press the physical Function keys on my keyboard, the macros will fire.
I want to explore an alternative method, using a variable Var_Num4Func to control which Function key to simulate.
Currently, its value is 7. With the macro shown below, it is supposed to simulate F7. I executed the macro, but the macro that is supposed to be triggered by pressing F7 is not executed.
I added the debug action group, to display the value of the variable Var_Num4Func. The action is successfully executed, displaying the value of the variable. I assume, then, F7 was successfully executed.
My question is: Does this mean that simulating a keystroke will fire the macro with that keystroke as trigger? Or did I do something wrong?
Thanks for your reply. But I'm not understanding whether your example solved my problem.
What I was trying to accomplish is this:
Let say, the initial value for the variable Var_Num4Func is 1.
When I execute this macro (Macro #1), since the value is 1, KM will simulate F1 press.
I hope the F1 then will trigger another macro (Macro #2) that has F1 press as trigger. → What I can tell is: it looks like the F1 keystroke is simulated, but but Macro #2 is not executed. This is my problem.
Then, Macro #1 will continue macro, which will set Var_Num4Func to Var_Num4Func + 1, turning its value to 2.
Then, when I execute Macro #1 again, since now, Var_Num4Func = 2. It will trigger the simulating F2 keystroke action, which is supposed to trigger Macro #3, which has F2 as trigger.
Then, Macro #1 will continue macro, which will set Var_Num4Func to Var_Num4Func + 1, turning its value to 3.
And, when I execute Macro #1 again, it will simulate F3 keystroke, and trigger Macro #4 which has F3 as trigger. And so on.
In other words, I used to need F1-F9 to trigger 9 macros. But with this new setting, I need only two macros, one to loop through F1-F9 keystroke simulation by pressing 9 times, the other macro to reset the value of Var_Num4Func to its initial value 1.
Thanks for the suggestion. However, I'm using the Simulate Keystroke for a reason. I have multiple sets of macros that use the function keys as trigger, but I only activate one set at a time. I should have mentioned this.
I'm more curious about why Simulating Keystroke does not trigger the macros that uses the keypress as trigger?
Note that whether or not a key typed by Keyboard Maestro itself will trigger a hot key (and thus be swallowed and execute a macro) or not (and thus go through to the application is not defined - either behaviour may happen and which behaviour happens will vary depending on many unpredictable factors.
If I press the hotkey and it is also swallowed, then it makes more sense. But now, when I press the physical key, the macro is triggered, but simulating the hotkey press does not trigger the macro. I'm puzzled...