How to enable zooming only when the scroll is rotating?

10 views (last 30 days)
Hello all.
I have a script that tries to enable the zoom in/out when the mouse wheel is scrolled only. In the following example, the zoom is open when I scroll and remains for 1.0 sec before turning off again.
I am wondering if there is a way to construct MATLAB to allow the zoom only if the wheel is scrolling, and disables the zoom once I stop the scroll, instead of doing it for 1.0 second each.
rgbImage = imread("peppers.png");
imshow(rgbImage)
hFig = gcf;
set(hFig, 'WindowScrollWheelFcn', @scrollCb)
function scrollCb(varargin)
% This function enables zooming in/out for one second before disabeling it again
zoom on;
pause(1.0);
zoom off;
end
Please advise.
Thanks a lot

Accepted Answer

Walter Roberson
Walter Roberson on 20 Sep 2022
No, there is no way to do that.
Mice do not actively exchange state both directions with computers. There is no way for a computer to actively ask a mouse whether particular buttons are down or particular wheels are turning or if the user's fingers are resting on wheels.
Instead, mice send events to the computer. Button down, button up, wheel turn. There is no way to distinguish between user having removed their finger from the scroll wheel (intent to stop scrolling) compared to the user still having their finger on the wheel actively intending to continue scrolling but not having moved the wheel (perhaps studying the plot to figure out whether they need more zoom.) The best you can do is reduce the timeout, but you cannot detect end of scrolling as soon as it happens.
Apple famously had a one-button mouse, and there were numerous two button mice with no scroll wheel, and numerous trackpads; for all of those devices there are other detection mechanisms, and in some cases it might be possible to detect keyboard events or trackpad events. For example on some systems, scroll is left-shift and mouse movement and you might potentially be able to snoop the event stream to determine when the keyboard left shift is released (in some operating systems that might require elevated privileges.) But on mice with scroll wheel, the generated event is simply "Wheel2 Movement by -19" and you cannot tell whether the user is done or not.
  1 Comment
Ahmad Gad
Ahmad Gad on 20 Sep 2022
Oh, I see. That is all new to me. Thanks a lot for the informatin. I will stick to what I am currently using since It seems to work fine for me.

Sign in to comment.

More Answers (0)

Categories

Find more on Desktop in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!