简体   繁体   English

鼠标全局挂钩 - WM_MOUSEMOVE 延迟

[英]Mouse Global Hook - WM_MOUSEMOVE delay

Okay so there are plenty of samples for mouse global hooking.好的,所以有很多用于鼠标全局挂钩的示例。

My issue is how can I add a timer/delay for mouse movement.我的问题是如何为鼠标移动添加计时器/延迟。

What is the way of doing this?这样做的方法是什么? I thought maybe I should Thread.Sleep() on detecting WM_MOUSEMOVE ?我想也许我应该 Thread.Sleep() 检测 WM_MOUSEMOVE ?

if (MouseMessages.WM_MOUSEMOVE == (MouseMessages)wParam)
   {
     Thread.Sleep(delay)
   }

Thanks.谢谢。

i'm afraid you cannot slow down the mouse movement in this way.恐怕您无法以这种方式减慢鼠标移动速度。 Here you are just notified of a new mouse position, the system doesn't care what you do with this notification and how long it takes to complete, or if it sleeps.在这里,您只会收到有关新鼠标位置的通知,系统并不关心您对这个通知做了什么以及完成需要多长时间,或者它是否处于睡眠状态。

I suppose you should "record" the mouse position every "delay" time, and then every time a new WM_MOUSEMOVE event arrives (and the coordinates are different from the record ones), then you should "reset" the mouse cursor position to the saved coordinates.我想你应该在每个“延迟”时间“记录”鼠标位置,然后每次新的 WM_MOUSEMOVE 事件到达(并且坐标与记录的坐标不同),那么你应该“重置”鼠标光标位置到保存的坐标。

of course, this until the WM_MOUSEMOVE arrives within "delay" time.当然,这直到 WM_MOUSEMOVE 在“延迟”时间内到达。 Otherwise just record a new position and wait for the next event.否则只需记录一个新位置并等待下一个事件。

.NET have the Cursor.Position property that should allow you to move the mouse cursor where you want, other languages should have their analogous, but i've never tried it and i'm not sure it operates correctly in your "global" context. .NET 有 Cursor.Position 属性,它应该允许你将鼠标光标移动到你想要的地方,其他语言应该有类似的,但我从未尝试过,我不确定它在你的“全局”上下文中是否正确运行.

anyway messing around with the cursor position is something that can make the user very upset无论如何弄乱光标位置会让用户非常沮丧

maybe you don't want to stop completely the cursor for "delay" time, maybe you want to linear interpolate the new position with the previous one with a <1 factor?也许您不想在“延迟”时间完全停止光标,也许您想用 <1 因子线性插入新位置与前一个位置? this will slow down the mouse but with a smoother effect.这会减慢鼠标速度,但效果更平滑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM