有没有什么办法可以弄清楚鼠标事件是从哪里来的? 我的意思是,如果我在 Windows 上编写 C/C++ 程序,并在其上获得鼠标单击事件,我如何才能确定该事件是来自鼠标驱动程序、触摸板,还是由应用程序发送(鼠标事件通过发送适当的消息(如 WM_LBUTTONDOWN)进行模拟)。
感谢您的帮助:)
最佳答案
这对于处于用户模式的应用程序是不可能的——鼠标事件通常不提供有关事件源的文档化信息。有一种方法可以通过 Win32 API 函数获取一些消息的额外信息 GetMessageExtraInfo但是没有安全的方法来解释这些数据。它是非常特定于设备的,没有记录并且永远不会保证永远存在。
要解决此任务,您需要开发自己的 Mouse Filter driver基于 Windows DDK 示例。
它的回调有输入参数MOUSE_INPUT_DATA
- 包含鼠标事件信息的结构。有字段 UnitId
:
UnitId Specifies the unit number of the mouse device. A mouse device name has the format
\Device\PointerPortN
, where the suffix N is the unit number of the device. For example, a device, whose name is\Device\PointerPort0
, has a unit number of zero, and a device, whose name is\Device\PointerPort1
, has a unit number of one.
关于c++ - 如何找到鼠标事件的来源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12622312/