Use mouse click as a trigger

I want to use a 2-finger mouse click as a trigger for the Application Switcher but can't find a way to do that.

I think it's possible to run a piece of KM code in an infinite loop that constantly polls to see if the mouse buttons are both down, and then it can trigger any action that you want. Do you like this solution? It may be sufficient for your needs. Like this: (I'm not sure how well this work, but it's a start. The problem is that this code doesn't ABSORB the mouse clicks, so you may not be happy if you use this over an app.)

But KM doesn't have native triggers for any mouse clicks.

However KM does have a USB Device Key trigger, which can capture some mouse clicks (it may depend on the type of mouse you have.) The problem with this is that KM doesn't "absorb" the mouse clicks when used with this trigger, so if you create a macro to detect a simultaneous click, the click will still be send to the application under the mouse, which is probably not what you want.

Is your mouse a programmable mouse? If so, it may be possible to REDEFINE the primary mouse buttons to different USB key codes and then have KM intercept them completely so that ALL mouse clicks are absorbed by KM, which may make it possible to do exactly what you want. I actually did this once, several years ago. For some reason I'm not doing that anymore, and I don't remember why. But not all mice are programmable, and even the ones that are sometimes don't let you redefine the primary mouse button.

Are there actually mice that give a unique code upon two buttons being simultaneously clicked? I suppose it would have to take the form of the first button being held while the second were clicked.[1]

If the mouse is a Magic Mouse, could it be that a “two-finger tap” is the intended trigger? BetterTouchTool could respond to that and send Keyboard Maestro a different sort of trigger altogether.[2]


  1. Oh, Apple wants to help me with my grammar. Apple.
    image ↩︎

  2. A different sort of trigger. ↩︎

For this I would recommend BetterTouchTool instead. Keyboard Maestro can probably be made to do it, but I think BetterTouchTool can do it more easily and reliably.

I assumed you're wanting to use it with the Magic Mouse. I don't have one with me to test at the moment, but I tried it with a trackpad gesture instead and it worked very well. It's the same action for both though:

Great question! I couldn't find a good answer, without 3rd party software, other than QMK firmware allows it.

I did not recommend an output for triggering Keyboard Maestro because there are alternatives, and they may not be equal in practice. @hemicyon’s screenshot shows the use of Osascript, but I had wondered whether, say, a synthesised key combination action in BTT might reach a KM macro a fraction of a second sooner than a script—and whether that would even matter might depend upon the sort of mousing being done (e.g. gaming versus graphics).

Agreed. I just quickly threw that together to test it before posting. I was sure it should work because I pass other things between BTT and KM, but I'd never tried the application switcher. There was no reason it shouldn't work, I just like to double check.

It’s interesting to see that there are indeed mice that use QMK! Example

I would happily bet that OP was not referring to such a mouse, though; they must be very rare, surely always DIY… and not the sort of thing that an owner would forget to mention in conversation! :smile:

I don’t like to stay too long in BetterTouchTool. As someone who is used to the Keyboard Maestro editor, using BTT is like trying to write left-handed (“I have to specify the trigger first?!” :scream:).

Yes, Magic Mouse. I have BTT and I've done this before with it, but right now it is not responding to the trigger even after reinstalling BTT and I've been unable to get help on the BTT forum.

Hm. I'm on BTT v5.444 and it's working for me—the action at least, as I said I don't have a Magic Mouse with me just now. If you copy/paste the BTT action to a different trigger, does that work? If you assign a different action to the 2-finger click trigger, does that register? I'd try those steps first to determine whether there's a problem with the action or the trigger. Another thought, when I first triggered the application switcher from BTT, Mac threw a permissions prompt to allow BTT to control KM; perhaps double check that your permissions are correct as well.

When you say “it is not responding”, do you mean your Keyboard Maestro macro? If so, “not responding” assumes:

(1) that KM is receiving a trigger that the macro can respond to;
(2) that the macro should respond;
(3) that you are sure about when the KM is working, and when it isn’t (it’s unlikely to be the case, but just be sure that the apparent lack of results are not due to an error in the macro).

On point (1), see below in addition to @hemicyon’s tips about permissions. On point (2), check that the macro is enabled and active. On point (3), check the logs or add an alert action to the macro.

It seems that we have by now established that the workflow that you are used to can be summarised as follows, but let us know of any other factors that have not yet been mentioned.

Magic Mouse → BTT macro (if I may use that term!) → your KM macro.

You need to find out where in that chain something is not going according to plan.

Examples of things to investigate:

  • Is the BTT macro being triggered?
  • Is that macro outputting what you expect it to? (Is the outputted trigger via osascript, and if not, what method are you using?).
  • Is that means of triggering reaching KM? (e.g. Permissions issues).
  • Is the macro “not responding” to the BTT macro’s trigger or rather not receiving the trigger?

At least this is easy to check. BTT has a section called “Recently Used”. Everything that has been triggered by BTT is displayed there in the respective order.

image

I'm not sure if this helps, but if I want to reach BTT via KM, or vice versa, I use this script

1 Like

This is getting overcomplicated, so let me simplify it:

I don't like using CMD-Tab to trigger Application Switcher. I've previously set up a 2-finger click with Magic Mouse using BTT (which is now in my muscle memory), but for whatever reason that is not working.

I came here because I wondered if I could achieve the same thing using KM. It seems like that can't be done, at least without bending my brain into a pretzel.

Per Frankb, yes the macro does show up in BTT's Recently Triggered but the action has not actually taken place.

People have tried their best to figure out your usual way of working, and help find an answer to a question that was not as clear as you may have thought it was.

If you had asked “Can Keyboard Maestro respond to two-finger taps from a Magic Mouse, like BetterTouchTool can?”, we would have understood and you would have immediately been told that the answer is “no”.

KM macros can respond to Magic Mouse taps indirectly, but require the intervention of BTT—or maybe other software that I do not know about—and some of us mistakenly thought that that was what you wanted help with. Oh well.

Maybe you could find other software to stand in for BTT, but no, KM is not it.

2 Likes

Since you said you couldn't get much help in the BTT forum, I gave you some suggestions to diagnose this; did you try them?

Here's what I've done. Reassigned 2- finger click to Open Launchpad. If I click on the circled arrow Launchpad does open, but NOT with 2-finger click. 3-finger and 1-finger clicks do what they should. Neither 4-finger click nor any other gesture I've tried will open Application Switcher.

Hm. That is unusual. It almost sounds like there's a trigger conflict somewhere, but I'm not sure where it could be. I wonder too if maybe that specific trigger became corrupted? I would try deleting it completely and creating a new 2 Finger Click trigger with a simple native action to test that, and then investigate if there are any possible conflicting triggers or automations.

This is also odd. How you are triggering the KM macro in the BTT action? [edit] Oh wait, you're using BTT's native action to activate the Application Switcher. Are you also using KM's Application Switcher macro? This shouldn't really make a difference, though, because both are working for me.

You could use a USB Device Key trigger to your left mouse button, and then an If/Else checking if the right button is down to this. I don't usually like to use a left click as a trigger, but in this case it seems to work ok with my (very limited) testing.