鼠标滚轮滚动 - 如何捕获滚动开始和停止之间的时间间隔?
有没有办法捕获鼠标滚轮滚动开始和停止之间的时间间隔?实际上,我想捕获当我快速滚动鼠标滚轮时滚动开始和停止之间的间隔。
我已经看过 MouseWheel 事件,但它不能满足我的要求。在某种意义上,它总是给出 Delta 120 或 -120 的值,但我想根据鼠标滚动的速度调用一个函数,例如,当我正常滚动鼠标时,我想执行函数 1,当我非常滚动鼠标时,我想执行函数 1。我想快速执行功能2。换句话说,有什么方法可以区分鼠标滚动的高速和正常速度。
任何建议将不胜感激。
Is there any way to capture the time interval between mouse wheel scroll start and stop? Actually I want to capture the interval between the scrolling start and stop when I very quickly scroll the mouse wheel.
I have already looked at MouseWheel event but it don't fulfill my requirement. In senes that it always gives a value of Delta 120 or -120 but i want to call a function depending on the speed of the mouse scroll for example when i scroll the mouse normally i want to perform function 1 and when i scrolled the mouse very quickly i want to perform the function 2. In other words is there any way to distinguish between the mouse scroll high and normal speed.
Any advice will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能捕获鼠标滚轮事件并查看它们之间的时间间隔吗?基本上,当您收到鼠标滚轮事件时启动计时器,然后在下一个事件中查看计时器的位置(以及事件之间经过了多长时间)以确定滚轮转动的速度?如果经过的时间小于某个阈值,则执行功能 2,如果快于某个阈值,则执行功能 1。
如果计时器关闭,您可能必须将其设置为执行功能 1,以防它们只执行一次滚动。
事实上,您可以这样做:
在鼠标滚轮事件中启动一个计时器(具有指示缓慢鼠标滚轮的间隔),然后如果计时器关闭,则执行功能 1。如果鼠标滚轮事件在计时器已关闭,然后重置计时器并增加计数器(以跟踪自您所做的事情以来车轮事件的数量),然后启动第二个(更长的)计时器。如果计数器大于某个阈值,则执行功能 2。当第二个定时器到期时,重置计数器。按照这些思路,您应该能够在车轮缓慢转动时启动功能 1,在车轮快速转动时通过几次“点击”来启动功能 2。
这段代码应该给出(非常肮脏的)我正在考虑的事情的指示。玩了一会儿之后,我不太确定这是一个好的解决方案......
can't you capture the mouse wheel events and see how long between them. Basically start a timer when you get a mouse wheel event and then in the next event see what the timer is at (and so how long has elapsed between the events) to determine the speed the wheel is being turned at? If the elapsedtime is smaller than a certain threshold, perform function2 and if it is faster than a certain threshold perform function 1.
You will probably have to set it to perform function 1 if the timer goes off in case they only do a single scroll.
In fact you might be able to do it this way:
start a timer (with an interval that indicates slow mouse wheeling) in the mouse wheel event, then if the timer goes off perform function 1. If the mouse wheel event happens again before the timer has gone off then reset the timer and increment a counter (to keep track of the number in wheel events since you did stuff) then start a second (longer) timer. if the counter is greater then a certain threshold perform function 2. When the second timer elapses, reset the counter. Something along those lines should give you the ability to fire function 1 when slow wheel turning and function 2 when the wheel is rapidly turned through a few 'clicks'.
this code should give a (very dirty) indication of the sort of thing I was thinking of. After playing a little I'm not really sure it's a good solution though....
看一下 Control.MouseWheel 事件。
Take a look at the Control.MouseWheel event.
根据 Sam Holder 的建议,我在这里发布了他的建议的修改版本,以帮助其他面临同样问题的程序员。
As suggested by the Sam Holder i am posting here a modified verion of his advice to help other programmers facing the same problem.