c++ - 判断鼠标是否水平移动(C++)

标签 c++ winapi mouseevent

我可以通过捕获 WM_MOUSEMOVE 消息来检测光标在我的窗口上的移动。此消息包含 x 和 y 坐标,但我需要弄清楚用户是否试图水平或垂直移动鼠标。如果 x 坐标的变化比 y 更显着,我想忽略垂直运动。我需要使用其他消息吗?谢谢!

最佳答案

David 是对的,您可能需要跟踪状态。但是,有一个功能,GetMouseMovePointsEx这将为您提供最多 64 个鼠标的先前坐标。您仍然必须有一个 map (或其他一些数据结构)来自己存储坐标,但是该函数应该为您做很多工作。再一次,我不确定该方法与更手动的方法相比如何决定鼠标从哪里开始,以便您知道要比较什么。 *(见下面的编辑)

一旦有了之前的坐标,就可以将起始位置与最新位置进行比较。如果差异大于某个任意数量(由您决定),则执行您的代码。

*编辑:请阅读我上面链接的GetMouseMovePointsEx 文档

The GetMouseMovePointsEx function searches for the point in the mouse coordinates history. If the function finds the point, it returns the last nBufPoints prior to and including the supplied point.

If your application supplies a time stamp, the GetMouseMovePointsEx function will use it to differentiate between two equal points that were recorded at different times.

An application should call this function using the mouse coordinates received from the WM_MOUSEMOVE message and convert them to screen coordinates.

关于c++ - 判断鼠标是否水平移动(C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20479462/

相关文章:

C++ 堆栈使用模板化链表 - 内存泄漏

c++ - 同时移动乒乓 Racket

delphi - 从 TBitmap.Palette 中提取的颜色错误

c++ - OpenGL 和 Qt : display a label on the mouseover

java - Pydev 中的自动补全 - Eclipse for wxpython

c++ - Linux 中跨进程的文件 I/O?

c++ - MediaFoundation + VP8 + 颜色格式

winapi - 带Windows CryptoUnprotectData的Rust FFI

javascript - 如何使用点击事件检测 Canvas 上的对象

javascript - 打开新的空白窗口,添加输入元素,然后将单击事件分派(dispatch)给不起作用的元素