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.
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.
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.
The world is not perfect, not even the world of buttons
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.
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.
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.
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:
z01 AppleKeyboardLeftControl_Released ∑ macro - sets a variable when the left control key is released.
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).
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.
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.
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.
I think having to press them in the proper order is not desired.
I also think it is not desirable for the press of button 4 to have to wait for a timeout to see if a right click happens within the predetermined time window. Pressing button 4 cannot look ahead to whether or not a right click will happen.
But what if that's not the right question?
I think the desired trigger is to have both button 4 and the right button down at the same time, regardless of the order the button down presses. So what if you separated button down and button up?
I'm wondering if the circular dependencies and press order problems can be untangled by using the button Release as the trigger.
If there is either a right button down or a right button up in between the button 4 down and the button 4 up, that means both were down at the same time. If not, then button 4 does it's only thing as soon as it is released, no waiting.
I'm not in a position to test this, but it seems like it might do what you want.