How to enable zooming only when the scroll is rotating?

9 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2022-9-20
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 个评论
Ahmad Gad
Ahmad Gad 2022-9-20
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Desktop 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by