Press and Hold actions with pause until condition

Hello all,

I'm hoping someone can provide some guidance. I'm using a Stream Deck, and I'm trying to configure a button for "Press to Talk" in Teams. I've configured two Macros. The first activates on press and holds option+space and sets a variable to 1. Then, it should pause until that variable is reset to 0. The second macro activates on button release and sets the variable to 0. Unfortunately, the release trigger doesn't appear to work while the first macro is paused. If I disable the pause action, the variable is toggled as expected. Here are the two macros. Any feedback is apprecaited!

Screen Shot 2022-08-15 at 12.22.06 PM
Screen Shot 2022-08-15 at 12.22.16 PM

Hi - welcome to KM’s Forum.

Since you’ve set your variable to a Calculation I think the condition to use in your Pause action should be:

The variable r3c1Pressed = 0

And not “is 0”.

That makes sense, and I appreciate the suggestion, but I just tried it, and both configurations perform the same way. The problem is that the release trigger is not recognized. So the variable is not reset to 0.

Here are some more details.

If I manually run "Release Press to Talk" from inside KM, then the variable is reset, and "Press to Talk" finishes as expected. Also, if I hold the button and press another key or click the mouse, then when I release the button the trigger fires as expected.

Observing debug, I can see that the release macro is not running. This is looking more and more like a bug. FYI, I am running on MacOS 12.5 with KM 10.1.1.

Thanks

Ah - OK.

You need to understand that is pressed is not the same as is pressed and held.

My bad for not spotting that.

I would suggest you have a single macro as follows:

Triggered when r3c1 is pressed

If r3c1Pressed = 0 then
   set r3c1Pressed to 1
   Do Talk actions
Else
   Set r3c1Pressed to 0
   Do End-Talk actions

Sorry - not at my Mac so can’t give you an actual macro! I hope you can make sense of this.

So to talk you just press the SD key and to stop you just press that key again.

I'm not near my SD right now, so I can't check, but apparently push and hold is already a thing...

Thanks again for the feedback, but that's not the functionality I'm hoping to achieve. I can accomplish that functionality with a simple keyboard shortcut that doesn't require Keyboard Maestro.

I'm really trying to replicate the "press and hold button to talk" functionality. Is this not possible?

It is, and it does work, but it only works if the app is active. The KM macro is bringing the window to the front so the keystroke actually works.

Could you use a SD multi-action; one action would activate the app and another would activate push-to-talk while held?

Very frustrating not having my SD to hand...

This sounds like an excellent work around. I wasn't aware I could configure multi-actions. I'll give it a shot!

On another note, I figured out that if I configure the macro using a key that isn't on the stream deck, it works fine. It appears to only be a problem with the stream deck buttons.

What about triggering the macro using a hotkey which is in fact emulated by the SD?

I tried that too with f15. No joy. Everything relies on KM recognizing the release of the SD button, and that's never registered.

Multi-function didn't work either because you can't hold a key with multi-function. It runs on button release.

I wonder if that might be an Fn key limitation...? I just got back and tested holding keys via SD hotkey actions and it seems to work. Maybe try a different hotkey?

Would you mind sharing your test macro?

There isn't one. I just tried holding a Stream Deck hotkey and it worked. So set one up to simulate ⌥Space and you're done (maybe).

Are you suggesting to setup the ⌥Space hotkey directly in the SD without using KM? I know that works. It doesn't bring Teams to the front first though. The KM macro should perform the following:

Upon press and hold of SD key:
Bring Microsoft Teams to the front
Press and hold ⌥Space
Pause until "condition"

Upon release of the SD key:
Set "condition"

The problem is that while the first macro is paused, the release of the SD key isn't recognized in the debugger. If I move my mouse or touch another key while I'm holding the SD key, then when I release the SD key, it is recognized in the debugger, and the second macro fires. This logic works with standard keyboard keys. For example, it works if the action key is left shift.

Ok I think I might have an idea of (one) problem. When you release the button, ⌘ and Space are being held down, so in order to register the release, the release trigger would need to be Stream Deck RC31 released *while* ⌘Space is held down, which can't be accounted for. (I have tested and confirmed that the release is not recognised if other keys are held. Simple modifiers would be fine, but that doesn't help us.)

In order to negate the trigger/keystroke conflict:

  • Can you activate/deactivate Push-To-Talk via AppleScript?
  • Can you activate/deactivate Push-To-Talk via a menu item?
  • Can you activate/deactivate Push-To-Talk via any means other than a key command?

So, this is what's confusing and why I'm not sure I agree with your logic on release a button while other buttons are pressed. Here's a sample macro with 2 triggers. This same macro works with the shift key trigger but doesn't work with the SD button trigger. This seems to be specific to the SD.

Screen Shot 2022-08-16 at 10.15.27 AM

According the the developer of KM - Peter Lewis - it isn't.

Have a look at this thread in the KM Forum and you'll see a pair of macros surprisingly similar to your own originally posted ones.

1 Like

I think your best bets are:

  1. Use AppleScript or a Menu Item to enable Push-To-Talk
  2. Have a second button right next to your Push-To-Talk button that activates Teams, which you'll press immediately before the main button.

It looks like he's trying to use KM to simulate a modifier key while he presses other keys. I'm not generating modifiers in this fashion, and I'm not pressing other keys while the usb device button is pressed. As you can see in my latest sample, KM is absolutely able to accomplish the goal as long as the button isn't on the SD.