I have the following segment of source code derived from this question in an example application as I learn about HID USB devices and Raw Input. I did an experiment where I ran this application on a Dell Latitude laptop which has a keyboard and two mouse like input devices, a touch pad with two buttons and a joy stick thingy with two buttons.
The source code piece looks like the following. This code is providing a listing of the HID devices into the Output pane of Visual Studio since I am running this example in the debugger so that I can inspect various data fields.
One issue that I ran into was that it appears that in the call to the function GetRawInputDeviceInfo()
using the RIDI_DEVICEINFO
parameter to retrieve the data of a RID_DEVICE_INFO
struct, I had to initialize the cbSize
member with the size of the struct or the function would not fill in the device information into the struct.
HRESULT hResult;
TCHAR szTempOutput[256];
PRAWINPUTDEVICELIST pRawInputDeviceList;
UINT uiNumDevices;
UINT cbSize = sizeof(RAWINPUTDEVICELIST);
GetRawInputDeviceList(NULL, &uiNumDevices, cbSize);
pRawInputDeviceList = (PRAWINPUTDEVICELIST)malloc(cbSize * uiNumDevices);
GetRawInputDeviceList(pRawInputDeviceList, &uiNumDevices, cbSize);
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT(" DeviceList Num Devices %d \n"), uiNumDevices);
if (SUCCEEDED(hResult))
{
OutputDebugString(szTempOutput);
} else {
// TODO: write error handler
}
TCHAR *psDwType [] = {
TEXT("RIM_TYPEMOUSE"),
TEXT("RIM_TYPEKEYBOARD"),
TEXT("RIM_TYPEHID")
};
for (int i = 0; i < uiNumDevices; i++) {
UINT cbDataSize = 1000;
TCHAR *pType = TEXT("Unknown");
RID_DEVICE_INFO DevInfo = {0};
char pData[1000] = {0};
// For each device get the device name and then the device information
cbDataSize = sizeof(pData);
GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, pData, &cbDataSize);
DevInfo.cbSize = cbDataSize = sizeof(DevInfo); // specify the buffer size
GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &DevInfo, &cbDataSize);
if (pRawInputDeviceList[i].dwType <= sizeof(psDwType)/sizeof(psDwType[0]))
pType = psDwType[pRawInputDeviceList[i].dwType];
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT(" DeviceList %d dwType = %d, %d (%s) name = %s\n"),
i, pRawInputDeviceList[i].dwType, DevInfo.dwType, pType, pData);
if (SUCCEEDED(hResult))
{
OutputDebugString(szTempOutput);
} else {
// TODO: write error handler
}
switch (DevInfo.dwType) {
case RIM_TYPEHID:
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT(" HID dwVendorId = 0x%x dwProductId = 0x%x dwVersionNumber = 0x%x\n"),
DevInfo.hid.dwVendorId, DevInfo.hid.dwProductId, DevInfo.hid.dwVersionNumber);
if (SUCCEEDED(hResult))
{
OutputDebugString(szTempOutput);
} else {
// TODO: write error handler
}
break;
case RIM_TYPEMOUSE:
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT(" Mouse dwId = 0x%x dwNumButtons = %d \n"),
DevInfo.mouse.dwId, DevInfo.mouse.dwNumberOfButtons);
if (SUCCEEDED(hResult))
{
OutputDebugString(szTempOutput);
} else {
// TODO: write error handler
}
break;
case RIM_TYPEKEYBOARD:
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT(" Keyboard dwType = 0x%x dwSubType = 0x%x dwKeyboardMode = 0x%x\n"),
DevInfo.keyboard.dwType, DevInfo.keyboard.dwSubType, DevInfo.keyboard.dwKeyboardMode);
if (SUCCEEDED(hResult))
{
OutputDebugString(szTempOutput);
} else {
// TODO: write error handler
}
break;
}
}
free (pRawInputDeviceList);
I ran this source two times. The first run was with the laptop as is. The second run was after plugging a Logitech two button scroll wheel (which operates as a third or center button) laser mouse into a USB port. The device information appears to see the Logitech as a three button mouse and the other two as a two button mouse. It also appears that the two different mouse input devices are seen as a single device and that the built in keyboard and the built in mouse have two different entries in the device list where as the Logitech mouse which was physically plugged into a USB port added only a single entry to the list.
DeviceList Num Devices 4
DeviceList 0 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \??\Root#RDP_KBD#0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x51 dwSubType = 0x0 dwKeyboardMode = 0x1
DeviceList 1 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \??\ACPI#PNP0303#4&2f94427b&0#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x4 dwSubType = 0x0 dwKeyboardMode = 0x1
DeviceList 2 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \??\Root#RDP_MOU#0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x2 dwNumButtons = 2
DeviceList 3 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \??\ACPI#PNP0F13#4&2f94427b&0#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x2 dwNumButtons = 2
DeviceList Num Devices 5
DeviceList 0 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \??\HID#Vid_046d&Pid_c00e#6&37d208f8&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x100 dwNumButtons = 3
DeviceList 1 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \??\Root#RDP_KBD#0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x51 dwSubType = 0x0 dwKeyboardMode = 0x1
DeviceList 2 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \??\ACPI#PNP0303#4&2f94427b&0#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x4 dwSubType = 0x0 dwKeyboardMode = 0x1
DeviceList 3 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \??\Root#RDP_MOU#0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x2 dwNumButtons = 2
DeviceList 4 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \??\ACPI#PNP0F13#4&2f94427b&0#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x2 dwNumButtons = 2
Looking in the Device Manager utility under "Mice and other pointing devices" I see two devices, "Logitech USB Wheel Mouse" and a "PS/2 Compatible Mouse". The Logitech mouse shows a Device Instance Id of HID\VID_046D&PID_C00E\6&37D208F8&0&0000
and the PS/2 mouse shows a Device Instance Id of ACPI\PNP0F13\4&2F94427B&0
.
The Logitech mouse also shows in the "Human Interface Devices" list with a Device Id of USB\VID_046D&PID_C00E\5&38366AA3&0&1
.
There is a "Standard 101/102-key" keyboard in the "Keyboards" list with a Device Id of ACPI\PNP0303\4&2F94427B&0
When I unplug the Logitech mouse from the USB port the fifth device disappears from the list when I run the application again and I am back to the original list of four devices.
Finally I ran this utility on a Titan-150 point of sale terminal manufactured by SAM4S. The terminal has a touch screen and a Magnetic Strip Reader (MSR). In addition I had a Logitech keyboard plugged into one of the USB ports.
DeviceList Num Devices 6
Dev No.: 0 dwType = 2, 2 (RIM_TYPEHID)
name = \\?\HID#DCO9000&Col02#6&178d2043&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
HID dwVendorId = 0x14e1 dwProductId = 0x9000 dwVersionNumber = 0x0
Dev No.: 1 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \\?\Root#RDP_KBD#0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x51 dwSubType = 0x0 dwKeyboardMode = 0x1
Dev No.: 2 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \\?\HID#VID_1C8A&PID_0203#7&1af96a6b&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x51 dwSubType = 0x0 dwKeyboardMode = 0x1
Dev No.: 3 dwType = 1, 1 (RIM_TYPEKEYBOARD)
name = \\?\HID#VID_046D&PID_C312#7&32af08f0&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
Keyboard dwType = 0x51 dwSubType = 0x0 dwKeyboardMode = 0x1
Dev No.: 4 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \\?\Root#RDP_MOU#0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x2 dwNumButtons = 2
Dev No.: 5 dwType = 0, 0 (RIM_TYPEMOUSE)
name = \\?\HID#DCO9000&Col01#6&178d2043&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
Mouse dwId = 0x80 dwNumButtons = 3
Looking at the list of USB vendor ids available from linux-usb.org I can see that the Logitech key board, device #3 with a vendor id 046d, and the PenMount 5000 Touch Controller, device #0 with a vendor id 14e1. It appears touch controller uses two additional USB devices, device #4 and device #5, which are presented to the Windows application as a two button mouse and a three button mouse respectively. These two USB mouse devices, virtual devices, provide a means to provide touches on the touch screen surface to applications using mouse messages allowing standard Windows applications to be used on the terminal.
However there is another device, device #2 with a vendor id of 1c8a, whose vendor id is not on the linus-usb.org list. That device seems to be the MSR device which is configured to act as a wedge keyboard device pushing the card swipe data to an application as a series of keyboard messages. The MSR does indeed act as a wedge keyboard device. When tried with a magnetic strip card with the Notepad application open and with focus, the card holder account data appears in the Notepad window.