如何在不限制屏幕大小的情况下跟踪鼠标移动? [英] How to track mouse movements without limiting it to screen size?

查看:33
本文介绍了如何在不限制屏幕大小的情况下跟踪鼠标移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WM_MOUSEMOVE 来更改鼠标位置.例如,在模拟旋钮"时,希望让用户无限制地使用鼠标上下移动.在这种情况下,我隐藏光标并使用 SetCursorPos 每次用户移动时更改其位置,并仅检测与原始位置的差异.

I'm using WM_MOUSEMOVE to get changes in mouse position. When simulating "knobs" for example it's desired to let the user go up/down with mouse without any limits. In this cases I hide cursor and use SetCursorPos to change its position every time user moves with it and detect just the difference from the original position.

不幸的是,它似乎不起作用 - 如果我设置鼠标位置,它有时会起作用,但有时是一个或多个像素,这是错误的.更大的麻烦是,在调用之后似乎传递了另一个 WM_MOUSEMOVE,不幸的是,它做了同样的事情,因为它想再次将光标移回原始位置.所以它会以无限循环结束或设置鼠标位置并接收消息,直到用户释放鼠标按钮.

Unfortunately it doesn't seem to work - if I set the mouse position, it sometimes works, but sometimes is one or more pixels away, which is just wrong. And even bigger trouble is that after the call another WM_MOUSEMOVE seems to be delivered, which unfortunately does the same thing as it wants to move the cursor back to the original position again. So it ends up in an infinite cycle or settings mouse position and receiving messages until the user releases the mouse button.

正确的方法是什么或有什么问题?

What's the correct approach or what's the problem?

推荐答案

原始输入系统可以做到这一点 - 它允许您注册未剪切或限制在屏幕边界内的原始鼠标输入.

The raw input system can do this - it lets you register for raw mouse input that isn't clipped or confined to the screen boundaries.

广义而言,您使用 RegisterRawInputDevices().然后您的窗口将收到 WM_INPUT 消息,您使用 GetRawInputData() 函数.

Broadly speaking, you register for raw input using RegisterRawInputDevices(). Your window will then receive WM_INPUT messages, which you process using the GetRawInputData() function.

请参阅以原始输入为例.

这篇关于如何在不限制屏幕大小的情况下跟踪鼠标移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆