Trigger by pressing a key while clicking the mouse

Is it possible to fire macro by holding down some mouse button and pressing some key?

For example, "Launch Google Chrome by holding down the right mouse button and pressing the C key".

(postscript)
Up until now, when switching between apps, I've been doing the following:
Option + C : Launch Chrome
Option + S : Launch Safari
Option + A : Launch After Effects
Option + D : Launch Discord
etc...

But, my left thumb hurt because pressing the Option key too often.
The Control and Shift keys are used for other operations, so I cannot use my little finger in place of Option. (Also, my little finger is already damaged.)
I also don't like to use the right Option key because I don't want my right hand to leave the mouse as much as possible.
So, I wanted a way to launch apps using the mouse and alphabet key.
Of course, there is no point in interfering with text input etc.

In other words, I want to launch each app using the alphabet keys without using my thumb or little finger.

There are no triggers for the primary mouse buttons. This is most likely because macOS does not provide an API for KM to access regarding those buttons.

However there may still be solutions that are close to what you want. That's because many mice have extra buttons that ARE detectable by KM. These buttons generate USB triggers which a KM macro can detect using the "USB Device Key Trigger" trigger.

If your mouse comes with software that allows you to redefine the PRIMARY mouse buttons as USB device keys, then you could do exactly what you want. But you didn't say what brand of mouse you use.

It would be far better to use MODIFIERS instead of mouse buttons to achieve this goal.

Another solution is to have a macro running in an infinite loop (which is an approach that most people object to) that checks to see if your right mouse button is "down" and then checks to see if the "C" key is down. This would probably work, but most people would say that this is a waste of resources. Personally, I say it's your computer and you can waste your CPU if you really want to.

1 Like

No -- and you can't really spoof it with a "USB device key" trigger because a) the right-click is passed through, so may open a contextual menu and b) the C key will either always be swallowed (set as hot key) or may/may not be typed (mouse button as hot key, waiting for the C). You'll have similar problems with a looping "checker" macro.

Assuming you want this so you can button-and-C for Chrome, button-and-S for Safari, etc, look instead at Conflict Palettes. You could, for example, set all your macros to trigger on the middle mouse button (making sure that isn't set to do something!) or the same hot key trigger, then keystroke to select from the resulting Conflict Palette.

1 Like

Of course you are 100% right, for most situations, and you are 99.9% likely to be correct in this situation also, but maybe the person is trying to use the mouse inside an app's window that ignores the right mouse button, or the other keys he wants to press. We simply don't have enough information yet.

1 Like

Thank you very much.
I've added more details about my purpose to the first question.
However, with your advice, I may have been able to resolve the issue.

I tried creating a macro like this.

Nice.

See how you get on with it. But there's a potential problem with timing and "pass-through" -- the C key has to be down before (or pressed milliseconds after) the mouse button, during which time it is also being registered by the frontmost application.

A possible option, if it is problematic, for an "easy left-hand key chord and right hand on mouse" would be to give all your macros the same ⌥Z (or X or C) hot key trigger so they trigger the Conflict Palette, and in KM's Settings->Palettes tick "Place Conflict Palette Under Mouse". The chord is an easy, relaxed, 3rd plus 2nd or 1st finger combo (no scrunching your thumb under your hand!) and you can set the Conflict Palette to have two, even three, columns to minimise mousing if you've a lot of apps to choose from.

1 Like

Here's another method that uses just one two-action macro to open whatever you specify:

Download Macro(s): SimpleLauncher.kmmacros (3.5 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.5
  • Keyboard Maestro v11.0.3

Note: To use the above macro, you'll have to change the trigger, as I set it to an Option click of my middle mouse button. You can use whatever you like; if you never use your middle mouse button, you could set it to use that button unmodified.

This macro takes advantage of the Prompt With List's action ability to return values that aren't what the user selected: Anything to the left of the double underscores in the text box is returned as the result of the selection, so the prompt can be whatever you want it to be, and the right value is still returned.

Onscreen, you'd see this:

But when you select Chrome, for instance, the variable is set to Google Chrome, because that's the actual name of the app. You can add as many apps as you like—just make sure you know their actual names (usually as shown when hovering their dock icons) to use on the left side of the text box.

As long as you make each keyboard shortcut unique, you can launch any app with a single keystroke plus Return. Yes, that's one additional keystroke, but it's an easy keystroke, and management of this launcher is really simple: Add or remove entries in the text box in the Prompt With List action, and you're done.

-rob.

1 Like

Whoops, realize now I left the brackets in—I was experimenting with ways to set off the initial letter that you can type to quickly select that shortcut, but the brackets mess things up if you type more than a letter.

If you use this, edit the text box and remove the brackets :).

-rob.