how to find where a mouse event come from?

浪子不回头ぞ 提交于 2019-12-25 03:06:01

问题


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).

Thanks for any help :)


回答1:


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.

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

Its callback has input parameter MOUSE_INPUT_DATA - structure containing mouse event info. There is the field 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.




回答2:


GetAsyncKeyState function can be used to check if the button was pressed, and unfortunately SendInput cannot trick this function. So you can simulate a mouse click, but the program can check if the button was really pressed.

So creating your own mouse driver is better. I needed a safe way so simulate mouse/keyboard behavior for my bot, and I wrote a detailled article on my blog http://poker-botting.blogspot.fr/2012/11/how-to-simulate-mouse-and-keyboard.html



来源:https://stackoverflow.com/questions/12622312/how-to-find-where-a-mouse-event-come-from

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!