How to detect the input device if mouse and touchpad are both enabled

后端 未结 6 1606
小鲜肉
小鲜肉 2021-01-15 12:14

I already have a WH_MOUSE_LL hook in my application, but need a different behavior for Mouse and Touchpad.

I know about Raw Input API, but have no idea how to use it

6条回答
  •  萌比男神i
    2021-01-15 12:54

    In your case, most probably, Raw Input will do. I've no experience with it beyond knowing its limitations regarding being able to capture input but not being able to prevent it from making after you have captured it, which means keystrokes and mouse events are going to happen for other applications even if you capture them with Raw Input. At last, this is what I have learned in forums abroad.

    I have built an alternative approach that is able to distinguish between devices, intercept input and also prevent this input from making. It's a C library that internally communicates with device filter drivers.

    I have two basic samples for device disambiguation at github:

    • identify
    • hardwareid

    The key difference between the two samples is that the hardwareid sample shows how to obtain an identifier provided by your device hardware, including vendor id, product id, and maybe some serial information. The problem is that commonly this provided information is not enough to disambiguate between two identical devices. They happen to be from the same vendor, have the same model, in sum, are equal but not the same. So what lasts to disambiguate is some kind of connection id, that may change at reconnection, but helps to disambiguate at runtime, and this is what the identify sample shows how to do.

    I have a macbook and was able to distinguish my magic mouse from my touch pad (at bootcamp) with my library.

    More docs at http://oblita.com/Interception.

    NOTE: currently the library has a limit of 10 keyboards and 10 mice.

提交回复
热议问题