Mouse as scroller Macro (v10.2)

I'm trying to create a macro where if I hold down modifiers, I can use my mouse to scroll in a window without clicking. I think my logic is correct, but the Simulate Scroll Wheel is telling me my variable is invalid [see attached image] and I can't figure out why. Any thoughts? Thanks.

Mouse as scroller Macro (v10.2)

Mouse as scroller.kmmacros (6.8 KB)

Read up on Text Fields.

Specifically the difference between Token Text fields and Calculation fields.

For example, the first action works, but probably should be

  • Set variable mouseY to Calculation MOUSEY()

The first If condition should be

If The variable mouseY != MOUSEY() - note that != is a numeric test, and so the field is a Calculation field, and so you do not use tokens like %Calculate%.

Similarly the conditions in the switch, is < is ca numeric test, so again the field is a Calculation field, and so the test should be against MOUSE(), not %Calcualte%MOUSEY()%.

Your Set Variable to Calculation (good) for mouseDelta should be MOUSEY() - mouseY (you are missing the () needed for the function call).

The currently invalid is simply because the action before it has not executed yet - Keyboard Maestro editor can only base actions on the current value of variables and other state, not on what they would be if the macro had run to that point. So currently mouseDelta has no value (as seen in the Set variable to Calculation action above) so the calculation mouseDelta is currently invalid - it is only orange because it could be valid if the variable changes value, which it will.

Thank you so much for your reply, Peter.

I fixed all of the calculation errors but am still hitting a snag. I've simplified the macro to troubleshoot and it seems the Simulate Scroll action isn't triggering, even though it seems it should be. The While condition is being met and displays as "currently true" and the mouseDelta variable is populating, but the Simulate Scroll never recognizes the mouseDelta variable. Even when I hard code a number into the Simulate Scroll, it does nothing.

I appreciate any time you can give to this. Thanks.

The parts I can see look ok.

Are you sure the simulated scroll wheel action can actually do whatever it is you are trying to do?

If you just have a macro that simulates the scroll wheel moving a fixed amount, and trigger it at an appropriate time (ensuring that it actually is being triggered!), does that work?

Yes, if I move the Simulate Scroll above the While action and hard code a number, it works fine.

Ahh, the while is finishing, immediately because the condition is false immediately, because the mouse has not moved yet.

Ah! Is there a better way to accomplish my goal? Maybe the While action isn’t feasible for this task.

I've made an even simpler version for troubleshooting purposes. You can see the mouseDelta variable has the correct value that isn't 0, but the next action which should scroll the page shows the value as 0. I can't fathom why this would be the case. Any help would be most appreciated. Thanks.

even simplier version

You have a While statement, but how long do you actually want the macro to operate for? When do you want it to stop repeating?

Currently it stops repeating if the Shift key is up, or if the mouse is >= the original mouse location, the latter of which happens immediately so it never repeats.

Without the While, the mouse has no chance of moving, and so it will never scroll anywhere.

Thank you so much for your help. I very much appreciate your time.

I did some tinkering and it seems to work now. As you suggested, I removed the variable condition in the While action. But the big one was changing the trigger device key from is pressed to is down. This set everything in motion properly. Now I'm trying to figure out how to solve the problem that I can't continuously scroll because the bounds of the screen are the only way to calculate mouse travel.

Here's the working macro:
this one works