Inconsistent Hotkey Trigger Press/Release

Hi Everyone,

I have the following macro.

Toggle
Triggered by any of the following:
The Hot Key ` is pressed
The Hot Key ` is released
Will execute the following actions:
If All Conditions Met
The key ` is down
Execute the Following Actions:
Enable Macro “Test”
Speak Text With Default Voice “Alex” at Fast Rate
On
Otherwise, Execute the Following Actions:
Disable Macro “Test”
Speak Text With Default Voice “Alex” at Fast Rate
Off

However, sometimes if I press and hold the hotkey down slightly longer like 2-2 seconds, it starts typing "````" and the release trigger doesn't work. It's very random. Sometimes it works, sometimes doesn't. It seems like depending on how long I hold it.

What's even more puzzling is that if I modify the macro to just say "On" and "Off" without enabling/disabling "test" macro like below, it always works perfectly 100% no matter how long/short I hold it!

Toggle
Triggered by any of the following:
The Hot Key ` is pressed
The Hot Key ` is released
Will execute the following actions:
If All Conditions Met
The key ` is down
Execute the Following Actions:
Speak Text With Default Voice “Alex” at Fast Rate
On
Otherwise, Execute the Following Actions:
Speak Text With Default Voice “Alex” at Fast Rate
Off

I'm also attaching the macros.

Could someone please help me to figure out what might cause this?

Thank you very much!

Toggle Test Macros.kmmacros (3.9 KB)

There appears to be some strange behavior occurring related to the Enable/Disable Macro actions that results in

A) the "Test" macro being selected in the KM editor as a side effect of running this macro (specifically, the "Enable Macro" action, as the "Disable Macro" part doesn't seem to have any adverse effects)
B) further input from the macro's trigger key failing to register in KM when A) happens, resulting in standard macOS behavior for repeating a held-down key

I took a look at my log and the only thing I found that seemed possibly related to this behavior was this message:

2017-11-26 21:07:23 Assertion Failed: mIsTriggerRepeating, file: /Users/peter/Keyboard Maestro/Project/Source/Triggers/TBaseTrigger.mm:117, value: 0
2017-11-26 21:07:23 Assertion Failed: mTriggerRepeater, file: /Users/peter/Keyboard Maestro/Project/Source/Triggers/TBaseTrigger.mm:173, value: 0

The rest of the log from the time I was testing these macros just looks like this repeated over and over:

2017-11-26 21:00:09 Execute macro “Toggle” from trigger The Hot Key ` is pressed
2017-11-26 21:00:11 Execute macro “Toggle” from trigger The Hot Key ` is released

Whatever's going on here, this behavior that causes an enabled macro to be selected in the KM editor would seem to explain why the macro works fine with those actions disabled (which I also confirmed was indeed the case). What version of macOS and KM are you using, @Chi? I'm on High Sierra 10.13.1 and KM 8.0.4.

In the meantime, I think I've found a way that works more reliably using a "Pause until" action instead of "If Then Else", with the only downside that it can't toggle the "Test" macro as quickly as "If Then Else" can when everything is working as expected. Here's the macro as text:

Toggle Test
Triggered by any of the following:
The Hot Key is pressed Will execute the following actions: Enable Macro “Test” Speak Text With Voice “Alex” at Fast Rate On Pause Until All Conditions Met The key is up
Disable Macro “Test”
Speak Text With Voice “Alex” at Fast Rate
Off

And here's the download link followed by an image of the macro:

Toggle Test.kmmacros (2.8 KB)

Thanks @gglick for the reply and the workaround.

However, the workaround keeps typing the accent character instead of swallowing it when holding down the accent key.

I use exactly the same setup: High Sierra 10.13.1 with KM 8.0.4.

No problem, @Chi. I'm afraid I don't have a solution for the repeated typing of the accent character; I can't even get it to occur consistently on my Mac, as sometimes the key repeats, and sometimes the macro works just as expected. However, I can think of one other workaround: unless there's a strong reason that you need to be able to toggle a macro by holding down a key instead of just pressing one, a version like this where the macro is toggled every time the key is pressed and an If Then Else action uses the macro's current state as the condition for speaking the appropriate word would seem to be one of the best alternatives:

Toggle Test 1.1
Triggered by any of the following:
The Hot Key ` is pressed
Will execute the following actions:
Toggle Macro “Test” Enabled
If All Conditions Met
The enabled is Macro “Test”
Execute the Following Actions:
Speak Text With Voice “Alex” at Fast Rate
On
Otherwise, Execute the Following Actions:
Speak Text With Voice “Alex” at Fast Rate
Off

####Download
Toggle Test 1.1.kmmacros (2.8 KB)

###Macro Library Image

If you absolutely need to be able to enable a macro by holding down a key and disabling it when the key is released, the only other option I can think of in lieu of this strange behavior being fixed is to turn off key repeating in the keyboard section of System Preferences, which is admittedly a rather blunt fix but may be the only workable solution for now.

I'm not sure I understand your use case, but perhaps this will help.

  1. Trigger your macro with ONLY one trigger: a normal hot key ` is pressed.
  2. Use the Long Press Key technique shown here:

I think that should resolve your issue. One note: since you are toggling the behavior, there should be no need to hold it down for much beyond 0.5 sec.

You might also want to use a Semaphore Lock action (KM Wiki) at the very beginning of your macro.

Questions?

Thanks @JMichaelTX and @gglick for the responses.
What’s funny is that if I get rid of the actions that enable and disable a macro, it works perfectly 100% of time. It says on and off accurately and never types accent.
It only fails when I have enable disable macro actions.
Wouldn’t this suggest that this might be a bug?
It almost like there’s a short timing that KM forgets to swallow the trigger when enable/disable another macro.
Basically I’m trying to make accent key to behavior like modifier such as option or command.
When an user holding the accent key, it enables a group with bunch of macrows with single letter triggers. When releasing it, it disables the macro group.
Thus, you could do something like accent+a, accent+b, and so on.
Also users have to be able to hold down the accent key and trigger other macros without releasing it.
Hold down accent to enable the macro group
press a to execute macro A
keep holding down the accent.
Press b to execute macro B
and so on…
Release accent key to disable the macro group.
Thank you for your help.

Hi @Chi,

I do believe that there's a bug in the enable macro action that is causing this strange behavior, as I found similar results when I tested it myself, so my subsequent posts were just for ideas to workaround the bug until it's fixed. However, now that I know what it is you want to accomplish, I can recommend a palette as a much better alternative. Palettes are explicitly designed to work with macros in this kind of temporal active state, and I can confirm that a setup like the one you want to use works fine with one. Here's a working example that should hopefully finally resolve this issue for you. The below download link contains four macros across two macro groups. The first macro is in the first group, and is only used to activate and deactivate the palette for the second group, which contains the other three test macros. The key is that the second group's macros are always enabled, meaning they are ready to use when activated, but are only active when the group's palette is visible, and the result is the kind of behavior you describe. In order to accomplish this, the macro group you want to activate while the accent key is held down must be set to

•Available in all applications
•Available in all windows

and the crucial part:
Shows/hides a palette when:

Here is the download link, followed by the macros as text, then as images. Download, import, and enable these macros, and you should be able to see how they work and how to modify them for your own purposes. As always, feel free to ask if you have any further questions!

###Download:
Palette Toggle Macros.kmmacros (7.6 KB)

###Palette Toggle

Triggered by any of the following:
The Hot Key is pressed The Hot Key is released
Will execute the following actions:
Show/Hide Macro Group “Test”
If All Conditions Met
The active is Macro Group “Test”
Execute the Following Actions:
Speak Text With Voice “Alex” at Fast Rate
On
Otherwise, Execute the Following Actions:
Speak Text With Voice “Alex” at Fast Rate
Off

###Test Group Macros

1
Triggered by any of the following:
The Hot Key 1 is pressed
Will execute the following actions:
Speak Text With Voice “Alex” at Default Rate
One

2
Triggered by any of the following:
The Hot Key 1 is pressed
Will execute the following actions:
Speak Text With Voice “Alex” at Default Rate
Two

3
Triggered by any of the following:
The Hot Key 1 is pressed
Will execute the following actions:
Speak Text With Voice “Alex” at Default Rate
Three

###Images
Palette Toggle

Test Group Macros

Thanks @gglick for the suggestion.
Only problem is that I use Mac screen reader called VoiceOver, and whenever the palette gets shown and hidden, there’s chatter from VoiceOver reading the window.
Otherwise, this works nicely!
@peternlewis, could you please look into fixing this? I’d really appreciate it.
Thank you!

Glad my suggestion was useful, @Chi! Now that I understand the full scope of your issue (i.e. why you want to have macros be activated by holding down a button and why you would prefer not to use palettes due to the VoiceOver issue) I have one last suggestion that will hopefully well and truly do the trick: try changing the "Show/Hide palette" option in the Palette Toggle macro from "Show/Hide palette" to "Activate/Deactivate", and correspondingly, change the macro group's activation options from "Shows/hides a palette when" to "Activated/deactivated when". Once you do this, I think you should finally have everything working as you like without unnecessary VoiceOver chatter. The sole caveat I need to tell you about is that in my testing, sometimes the toggled macro group would become toggled on instead of off, so that when the accent key is held down, it would de-activate the macros rather than activate them. To fix this, you can just make a new macro solely for the purpose of deactivating the toggled macro group to reset it to a deactivated state (the entire text of such a macro is

Deactivate Macros
Will execute the following actions:
Deactivate Macro Group “Test”)

and then the accent key toggle should always work as intended. Obviously I haven't tested this for a prolonged period, so I don't know how often you may have to reset the macro group's deactivation in this way, but hopefully it won't be too often.

To sum up, it seems like the key to solving this issue was to stop thinking about the problem in terms of macro and macro group enabling, and to start thinking about it in terms of activation. These are two KM concepts that are admittedly confusing since they sound like the same thing at first, but in this case they seem to be core to this issue. Essentially, what you wanted was a macro or macro group that was always enabled, but only activated when the accent key is held down. Hopefully that makes sense, and hopefully this resolves this issue for you once and for all (though again, feel free to report back if it doesn't)!

Thanks so much @gglick!
I finally got the way I wanted!
The following macro works perfectly.
Instead of toggle, I used activate when pressed, other wise deactivate using if action.
Thanks again!

Activate/Deactivate
Triggered by any of the following:
The Hot Key is pressed The Hot Key is released
Will execute the following actions:
If All Conditions Met
The key ` is down
Execute the Following Actions:
Activate Macro Group “Toggle Test Target”
Speak Text With Default Voice “Alex” at Fast Rate
On
Otherwise, Execute the Following Actions:
Deactivate Macro Group “Toggle Test Target”
Speak Text With Default Voice “Alex” at Fast Rate
Off

Hey yet again @Chi,

That’s great! I’m very glad to hear that :smile:

In that case, I have just one last request: since this turned out to be a fairly involved topic, would you mind marking my post that resolved this for you as the solution, so that any future readers can quickly see what it was? The solution button isn’t present on posts by default; instead, it’s hidden behind a button labeled “show more” and is labeled as “This reply solves the problem”. Thanks in advance, and I hope the ability to set up macros like this turns out to be fruitful for you!

Done! Thanks!

Enable/Disable macro is a very heavy handed action. It cause the macros to be changed, and reloaded in both the editor and the engine.

You generally do not want to use that for transient macros, you want to use activate/decativate Macro Group for things that are transient if at all possible.

Because the macros are reloaded by the engine, a lot of macro state is lost, and hot keys are unregistered and re-registered and such. I expect that is why you are running in to this sort of issue.

Thanks for the clarification, Peter! That makes sense. This turned out to be a very educational thread for me on the differences between enabling and activation :slightly_smiling_face:
By the way, just to be sure, did you perhaps mean "activate/deactivate" for this part?

Yes. I am clearly still asleep this morning. Fixed. Thanks.

1 Like

This issue I have is that Activate/Deactivate applies to a Macro Group, NOT just one macro. In my use case, I have been disabling macro 2 at the start of macro 1, and the enabling it at the end. Short of creating a special Macro Group for this, I don't see any alternatives.

Any options I'm missing @peternlewis?

Thanks @peternlewis for clarification!

Nope. In that case, the only option is Enable/Disable, and, as noted, it's a heavy hammer. For example, the state will sync between Macs if you have Macro Syncing.