获取鼠标运动输入而不是光标位置(C++)
我想让我的代码读取鼠标的运动,并相应地采取行动,例如,如果您要移动鼠标,则打印鼠标正在控制台中移动
,并且有点像这样。 (我使用的是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用原始输入api 为此。呼叫 要注册要监视的目标鼠标设备(可能有多个连接到PC),然后处理
wm_input
消息包含来自鼠标的原始输入数据的消息。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 handleWM_INPUT
messages containing the raw input data from the mouse(s).