获取鼠标运动输入而不是光标位置(C++)

发布于 2025-02-07 18:19:25 字数 300 浏览 3 评论 0原文

我想让我的代码读取鼠标的运动,并相应地采取行动,例如,如果您要移动鼠标,则打印鼠标正在控制台中移动,并且有点像这样。 (我使用的是Windows10。)

问题是,我可以找到很多具有鼠标光标坐标的文章,但找不到一个处理真正的原始鼠标输入的文章。我想这样做的原因是,当您的光标撞到边框并且无法进一步走时,光标位置不会改变,即使鼠标“物理”移动,该程序也不会识别鼠标运动。另一个问题是某些程序可以“锁定”您的光标以保持固定位置。例如,大多数FPS游戏都这样做。

因此,我想获得鼠标传感器给计算机传感器的原始输入,并利用它们而不是光标位置。

I want to have my code read the movement of the mouse and act accordingly, for example, if you are moving your mouse up, you print the mouse is moving up in the console and sort of like that. (I am using Windows 10.)

The problem is, I could find a lot of articles that take the coordinates of the mouse cursor, but couldn't find one that deals with the real raw mouse input. The reason I want to do it this way is that when your cursor hits the border and cannot go further, the cursor position wouldn't change and the program won't recognize the mouse movement even though the mouse is "physically" moving. Another problem is that certain programs can "lock" your cursor to stay in a fixed position. For example, most FPS games do that.

Therefore, I wanted to get the raw input that the sensor of the mouse gives to the computer and utilize them instead of cursor position.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2025-02-14 18:19:25

因此,我想获取鼠标传感器给计算机的原始输入,并利用它们而不是光标位置。

使用原始输入api 为此。呼叫 要注册要监视的目标鼠标设备(可能有多个连接到PC),然后处理 wm_input 消息包含来自鼠标的原始输入数据的消息。

Therefore, I wanted to get the raw input that the sensor of the mouse gives to the computer and utilize them instead of cursor position.

Use the Raw Input API for that. Call RegisterRawInputDevices() to register the target mouse device(s) you want to monitor (there could be multiple connected to the PC), and then handle WM_INPUT messages containing the raw input data from the mouse(s).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文