How to Trigger a Macro by Chording Two Mouse Buttons?

Hi,

I want to trigger macro by combination of two mouse buttons , for example: button 4 + right button.

How to do that?

Thanks
Roman

Not something I'd generally recommend due to the potential for interference with ordinary clicks, but if you want to experiment with it...

This enables the second macro whenever I press/release button 3 on my MX Master:

Two Button Mouse Trigger - Detect First Button.kmmacros (23 KB)

Macro screenshot

If I left click while this the following macro is enabled (by the previous one), then something other than a standard left-click will happen:

Two Button Mouse Trigger.kmmacros (21 KB)

Macro screenshot

NB: Make sure to enable the first macro and leave the second disabled when you import them.

Hi noisneil,

Thanks.

With your solution I can't trigger macro by individual button.
For example, when I use mouse button 4 + right mouse button to trigger macro #1 - I can't trigger macro #2 when I use only mouse button 4 as trigger.

Do you have a solution?

Thanks
Roman

It sounds like you want:

  • Button 4 + right-click = thing 1
  • Button 4 only = thing 2

The tricky thing with this idea is that you will have two dependencies:
1 - the behaviour of the right-click button will depend on whether button 4 is pressed.
2 - the behaviour of button 4 will depend on whether the right-click button is pressed.

The order in which you press the buttons will matter, so for this to work, you have to right-click while the other button is being held. In this macro, I'm using button 3. Be aware that the right-click will not be consumed by the macro, so an unwanted contextual menu might appear. Depending on your usage, you may want to enable the red action, which will dismiss the menu by simulating the escape key.

Two Button Mouse Trigger - Detect First Button.kmmacros (24 KB)

Macro screenshot

Two Button Mouse Trigger.kmmacros (22 KB)

Macro screenshot

I do not use a mouse and can therefore only report what others do. They "sacrifice" a button as a "modifier", let's say button a, it doesn't do anything on its own, but in combination with the others it does. a pressed plus b. but b can also do something on its own. Whether this can be done with KM, I don't know. Probably @noisneil knows.

What works for sure is this. The buttons have different functions depending on where the mouse is. So mouse over menubar, button a does something. Mouse somewhere button a does something else.

1 Like

That's a good approach, but wouldn't satisfy the requirement of having button 4 trigger a macro if clicked on its own.

The world is not perfect, not even the world of buttons :wink:

I see a way out. The macro with button 4 is triggered only by double-click. If button 4 is only pressed and held, it serves as a "modifier". Can this be done with KM?

No because modifiers can't be triggers on their own. The macro above solves the issue although, personally, I'd avoid using left or right clicks as triggers in any circumstance.

Yes, me too. I use a trackpad and swipe/click with two, three, four fingers, those are my triggers.

1 Like

Thanks, I will try.

Roman

I do exactly what the OP asks for, with minimal errors, using the app "Steermouse".

It installs as a System Preferences panel, acts as overall driver for the mouse, and Steermouse handles the chords nicely.

I turn KM macros into "Shortcut scripts" on MacOS Monterey. In the Shortcuts app, I add the new shortcut "to the dock" That makes it appear is an App in my "Users/YourUsername/Applications" which I then set to Open with my Steermouse chord. The shortcut uses "Run AppleScript with input", such as:

tell application "Pro Tools"
	activate
end tell
delay 0.25
tell application "Keyboard Maestro Engine"
	do script "Rename-to-Count-Selected"
end tell

Which makes my app focused then it runs the script no prob, just like traditionally running a macro in KM by script.

For the record I used Steermouse much longer than KM, but they work very well together, when you are mindful of any issues as described above. But I don't have many such issues after I check and fix a macro.

2 Likes

I don't know if it you're aware that you can directly "open" a Keyboard Maestro macro from SteerMouse by using a url format:

kmtrigger://macro=YourMacroName

Step by step instructions:

  1. Go to Safari (or any browser)
  2. Type kmtrigger://macro=YourMacroName in the address bar.
    (YourMacroName is... the name of the macro you want to launch)
  3. Go to SteerMouse and assign an open command to whatever button or chord you want.
  4. Drag the address from Safari to the "open" area of the steermoouse window.
  5. Enjoy

Edit: my main use for this is to get the possibility to launch macros from the scroll wheel or from chords.

The use of modifiers is very easy to assign in SteerMouse, so shift scroll launches a macro and command scroll launches another one.

2 Likes

I remembered this advice and tried it the next time I was assigning a macro from KM to SteerMouse. It worked great, so thank you very much for the free tip! It was cleaner and simpler than the method I described (which works nicely when there is other script stuff at work). I noticed I couldn't get it to work in Chrome, but luckily you suggested Safari, which worked perfectly.

1 Like

Modifiers can be used as triggers. And using them in a multi-press macro is very powerful.

You can use a modifier with another key as a trigger, but not a modifier on its own.

I am not the best 'poster' so please forgive the ruff edges here.

The Multi-Key concept comes from our friend @DanThomas

MACRO: HotKey Multi-Press Template (Double-Press, Triple-Press, Etc.)

This multi press key was set up for my Kensington expert mouse and I didn't have time to 'convert' it to be completely set up for the left control key, but it does basically work for the 1 and 2 press options, both short and long.

The following macros are:

  1. z01 AppleKeyboardLeftControl_Released ∑ macro - sets a variable when the left control key is released.

  2. z02 Display Large Duration|Message ∑ - is simply for a large display with timing options that I use (don't know attribution, sorry and thanx), (didn't have time to adjust all the display actions to be native KM).

  3. z03 Multi Left ⌃ Control Example no long presses ∑ K0152 - this is the best place to start for basic modifier key being used as a trigger. 1,2,3,4 or 5 presses. No long press is accepted.

  4. z04 Multi Left ⌃ Control Example w/long presses also ∑ K0153 - this is very messy down in the macro, please forgive, but again, it's fairly functional for the 1 and 2 presses both long and short. And the long presses can be with other modifier keys. The matrix is pretty endless.

So yes, modifier keys can be used on their own as triggers, without another key, by themselves or in conjunction with them being long pressed, long pressed with the addition of another modifier key, multi tapped by themselves or multi tapped with additional modifier keys added after the multi tap.

z01 AppleKeyboardLeftControl_Released ∑.kmmacros (2.5 KB)
z02 Display Large Duration|Message ∑.kmmacros (5.0 KB)
z03 Multi Left ⌃ Control Example no long presses ∑ K0152.kmmacros (36.7 KB)
z04 Multi Left ⌃ Control Example w:long presses also ∑ K0153.kmmacros (233.3 KB)

I'm aware of Dan's multipress macro and used his keypress counting method as part of this.

Can you just clarify how you set the trigger to be a modifier? I'm not by my mac at the moment so can't check your examples, but I must be missing something as single modifiers cannot be used (as far as I'm aware) as hotkey triggers. I don't think it's a good idea either, but that's beside the point.

Hey @noisneil
Under 'triggered by....'
Select 'USB Device Key Trigger'
Click in the blank field with 'none' text in it
Press desired modifier key.

1 Like

Would you believe I've gone all this time not knowing that?! Something new every day...

1 Like

I hear ya! it's just incredible... also, best forum ever.

BTW, I see some of the macros you are making, and the time you spend helping others. Thank you for both!

I in a past life was a 'major' =) Pro-Tools guy and used Quickeys extensively...

Got out of audio, and later made the transition to KM in 2016.

KM is just an awesome app...

Cheers
Troy

1 Like