如何找到鼠标事件来自哪里? [英] how to find where a mouse event come from?

查看:116
本文介绍了如何找到鼠标事件来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以弄清楚鼠标事件来自哪里?
我的意思是,如果我在Windows上编写一个C / C ++程序,并得到鼠标点击事件,我如何找到这个事件是来自鼠标驱动程序,触摸板,或者如果它是由一个应用程序(通过发送类似WM_LBUTTONDOWN的适当消息来进行鼠标事件模拟)。

Is there any way to figure out where did a mouse event come from? I mean, if I code a C/C++ program on Windows, and get a mouse click event on it, how can I find if this event come from a mouse driver, a touchpad, or if it was send by an application (mouse event simulation by sending appropriate message like WM_LBUTTONDOWN).

感谢您的帮助:)

推荐答案

对于用户模式下的应用程序 - 鼠标事件通常不提供事件源上的文档信息。有办法通过Win32 API函数获取一些消息额外信息 GetMessageExtraInfo ,但没有安全的方法来解释这些数据。

This is not possible for an application in user mode - mouse events generally don't provide documented info on event source. There is the way to obtain some message extra info by Win32 API function GetMessageExtraInfo but there is no safe way to interpret this data. It is very device specific, undocumented and never guaranteed to ever present.

要解决这个任务,你需要开发自己的鼠标过滤器驱动程序基于Windows DDK示例。

To solve this task you need to develop your own Mouse Filter driver basing on Windows DDK sample.

它的回调函数有输入参数 MOUSE_INPUT_DATA - 包含鼠标事件信息的结构。有字段 UnitId

Its callback has input parameter MOUSE_INPUT_DATA - structure containing mouse event info. There is the field UnitId:


UnitId 鼠标设备的单位编号。鼠标设备名称的格式为 \Device\PointerPortN ,其中后缀N是设备的单元号。例如,名称为 \Device\PointerPort0 的设备的单位编号为零,设备名称为 \\ \\Device\PointerPort1 ,单位编号为1.

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.

这篇关于如何找到鼠标事件来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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