I am writing a WPF app in which I use RawInput.Sharp to invoke the RawInput API and I'm able to obtain the mouse list and listen to the mouse event I'm interested in. No problem for that part.
However, when I want to record the events from my mouse, I notice that it has different information when connected using the USB receiver and plugged with the USB cable.
Taking my mouse, which is a Logitech G Pro Wireless, as an example:
- When connected with the USB wireless receiver, I see "USB Receiver" in the "Settings/Devices" in Windows 10;
- When plugged with the USB Cable, I see "G Pro Wireless Gaming Mouse" in the same place.
What I get from RawInput API is similar. Product name, produce ID, device path, device handle, etc. are all different...
Is it possible to know that these two devices from the device list are of the same mouse?
UPDATE 1: clarification of the question
I want to use this app to count how many times the left button of my mouse is clicked. I'm now able to listen to the click event and record it.
However, when I want to go one step further to make the app only listen to one of my mice (e.g. the GPW), I got 2 problems:
- GPW itself becomes 2 different devices when used wirelessly and plugged with USB cable. There seems no way to automatically identify and merge these devices.
- My keyboard's USB receiver also appears in the device list, with the same name of my mouse's USB receiver, when I grab only "mouse" type of devices.
Here's what I see from Settings/Devices in Windows 10 when both of my mouse's and keyboard's USB receiver are plugged, and my mouse is plugged with USB cable:
The devices obtained using the following code which calls RawInput.Sharp:
var devices = RawInputDevice.GetDevices();
foreach (var mouse in devices.OfType<RawInputMouse>())
{
Text += "\n" + mouse.ManufacturerName + " " + mouse.ProductName + " " + mouse.Handle + "\n\t" +
mouse.DevicePath + " " + mouse.VendorId + " " + mouse.ProductId + " " + mouse.UsageAndPage;
}
Definition of RawInputDevice.GetDevices():
https://github.com/mfakane/rawinput-sharp/blob/master/RawInput.Sharp/RawInputDevice.cs#L109
By the way, both USB receivers also show up if I change devices.OfType<RawInputMouse>() to devices.OfType<RawInputKeyboard>().


You can try to match them with HidD_GetSerialNumberString on a device interface handle. To obtain handle you need to call CreateFile on that
\\?\HID...device interface file name. Also mouse devices are opened by system for read and write exclusively - so you need to providedwDesiredAccessas zero, anddwShareModeasFILE_SHARE_READ | FILE_SHARE_WRITEto open handle (which cannot be used to read HID data but can be used to read various HID attributes).But not every HID device is providing serial number...