Help creating a macro that will hold "⌥+Click" for as long as I hold the defined key

Hey guys,

I've got an app that requires me to ⌥+Click on a button in order to see part of it, and what I want to see is only there while I keep the ⌥+Click held. The moment I drop the mouse click, that part of what I need to see goes away. Once I'm holding the mouse click, I CAN drop the ⌥ key though, but I can't drop the mouse click.

So what I need is to make all of that happen, when I press a certain key. While I HOLD the "" key, I need to:

  1. Move the mouse to a part of the program's UI
  2. Press and hold ⌥
  3. Left click and hold the mouse until I drop the "" key again.

Any ideas?

I had a similar situation. I’m not at my Mac right now to point out the specific actions, but it will require you to use some AppleScript. Something like:

Hold down option
Click at current location
End Hold

If you haven’t used AppleScript before, give it a shot! It’s a lot simpler than using more advanced scripting languages.

Stepping over item number 1. in the list since I don't have access to your program's UI, and also feel it's probably best you manually position the cursor before triggering a macro; I believe I've created a macro that accomplishes the tasks set out by items 2. and 3.

Testing is a little difficult, as I struggled to find similar UI elements of a program that responded in a similar fashion. But thankfully, some of the system menu bar icons do just that: holding down the option key, as you probably know, reveals an alternative menu when clicking on the likes of the Wi-Fi, bluetooth and volume menu bar icons. Moreover, one is free to release the option key (or keep it held), but the mouse button must remain down for the menu to remain visible.
small caveat: this is true if it's instantiated via a mouse press, rather than a mouse tap, the latter of which separates the menu's dependency from the mouse button status. However, this doesn't interfere with our experiment, so we can ignore this.

Pressing and holding a mouse button programmatically is not something I'd down before, but I did it in the end via JavaScript for Automation (JXA). The keypress (⌥) was trickier, so I resorted to straight forward AppleScript, which implements the option-down/up key presses very easily. This is why the scripting portions of the macro are an odd mixture of Apple-cum-JavaScript, which wouldn't be my typical approach.

The second objective was to have the macro initiate upon pressing of a hotkey; and cease upon releasing of the same hotkey. In fact, this is an illusion: on pressing of the hotkey, the macro is triggered a first time, which deploys the programmatic mouse/key down events; then the macro terminates, however, the mouse/key down states persist. So in between pressing and releasing of the hotkey, the macro isn't firing or doing anything. It then gets triggered a second time when the hotkey is released, and this sends the signal to change the states of the mouse button and option key to Up.

Here's the obligatory screenshot of the macro:

Mousedown + ⌥.kmmacros (21.4 KB)

The macro is current set to trigger upon depressing of the control (⌃) key, and again upon releasing of it. You can change this, but perhaps test the macro using the current settings to begin with, so if changing the hotkey causes it to respond poorly, you'll know it was due to the choice of hotkey and not the macro itself.

Obviously my testing has been limited, basically to this:

Option-Click

Here, I'm attempting to demonstrate the macro in action, which is difficult to do without relying on your faith that I'm not simply pressing and clicking the mouse button myself. In fact, my Keyboard Maestro menu bar icon is the 𝑥 symbol directly to the right of the volume icon, and it flashes whenever a macro is triggered. The menu that pops up is, indeed, the menu one gets when option-clicking-and-holding the left mouse button, and it vanishes once the mouse button is released.

But this is no guarantee it will be sufficient for your particular use case.

On a final note, I've selected a variable called bool that is used to determine which action to take each time the macro is fired. It's probably best that this variable isn't used elsewhere in another macro. It won't cause too much trouble if it is; but the initial run of the macro relies on the value of bool being anything other than true (including unset), so if it were true from the start, it would simply do nothing until the macro is triggered again. A minor inconvenience, but worth highlighting.