Simulate Option + Scroll wheel up (or down)

Hi all,

I know that Keyboard Maestro can’t simulate ‘Opt’ key, however it is possible to do that via AppleScript:

tell application "System Events"
   key down option
end tell

What I am trying to achieve is zoom in/zoom out in the applications like InDesign or Illustrator. Currently I am using cmd + =/- which is a bit frustrating especially in InDesign: It doesn’t zoom whenever my mouse cursor is (it zooms instead to a selection, totally disrupting the view position).

Perhaps there is a way doing it in AppleScript/JavaScript?

OK, a couple of things (and I’m smiling as I type this, so I’m not actually ticked):

  1. It might have been nice to know that if I run your AppleScript, how the heck do I get the option key back up? I had to reboot, because I couldn’t get it “unstuck”. Important safety tip, that would have been useful yesterday! (to mix quotes from two different movies). :slight_smile:

  2. Since that script does appear to work, I would imagine you could use it along with a “Simulate Scroll Wheel” action.

  3. Don’t forget the aforementioned “key up” AppleScript afterwards. :slight_smile:

I think this works only when there is a window with a vertical scroll bar.(?)

Well, I just tried it with Gimp, while manually holding down the Command key, and it zooms in and out just fine. No scroll bars present.

And let me tell you, if it works in Gimp, it'll probably work anywhere, because Gimp doesn't always play well with KM and the mouse. :slight_smile:

Yes, you are right. It also works together with the key down/up AppleScripts. (At least in GraphicConverter.)

1 Like

Hi @DanThomas ,

I should include the note that my AppleScript permanently holds Option key until you restart your Mac. As you mentioned before I forgot to include key up!

So far I made this (it works but it's not very responsive):

That’s how I would have coded it, so it looks good to me.

I wonder about the lack of responsiveness. It’s quite possible you’re right. But I can’t help but wonder if it’s a perception issue? The difference between pressing a key vs. using a scroll wheel?

Also, I assume you’ve tried adjusting the scroll amount, but if you haven’t, certainly try that.

PS: I’d consider creating a macro for hotkey = (or something with , anyway) that just does a “key up” on the option key. That way, if it gets stuck down, at least you can force it back up.

Looks like you have a solution, but I thought I'd mention this as an alternate, and for other readers.

I don't have InDesign, so I can't test this, but my Logitech mouse has a control panel where I can (and do) set the scroll wheel to zoom AFTER I press/release the scroll wheel. Works great in every app I've tried it (Chrome, Safari, Evernote)

I am using MX Revolution (old but good!) and I have no way of using zoom for my scroll wheel:

Even if I assign zoom to let's say thumb wheel: it doesn't work at all... I am trying to figure out AppleScript for scroll wheel, so far I found this but it doesn't seem to work [link]:

do shell script "
/usr/bin/python <<'END'
import sys
import time
from Quartz.CoreGraphics import *

def scroll_up():
    event = CGEventCreateScrollWheelEvent(None, kCGScrollEventUnitLine, 1, -1)
    CGEventPost(kCGHIDEventTap, event)

scroll_up()
END"

Edit:
The code above works for scrolling, but it's awfully slow (takes like 2-3 sec to scroll)

I ended up going down this path with Control instead of Option, but can’t get it to work. Please see my attempts and give me help if you can.

In general it does work here. (The strange thing is that it works only at every second launch of the macro, but this may be a glitch with my local environment.(?))

You can see the key strokes with the help of the Keyboard Viewer or with the Key Codes app. You can see the scrolling if you test the macro while a scrollable window is on the screen.

But it does not work for the Accessibility Zoom.

The only way I’ve found to make the zoom window appear is assigning a hotkey that involves the Control key (so that it is held down physically on the keyboard when the macro launches).

Probably the Accessibility Zoom is designed this way (to only accept real keystrokes).

I copied your response to the page with my other post and responded there.