Background
I am trying to get the touch coordinates from precision touchpads with C++ in Win10 with the program running in background.
Research
Rawinput can get data in background.
I can get the data with these usage id and pages from microsoft :
Member Description Page ID Mandatory/Optional
X X coordinate of contact position 0x01 0x30 Mandatory for T Optional for C
Y Y coordinate of contact position 0x01 0x31 Mandatory for T Optional for C
I can put the two of them together with HIDP_functions, from this answer.
Code
case WM_INPUT: {
UINT dwSize;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize];
if (lpb == NULL) {
return 0;
}
RAWINPUT* raw = (RAWINPUT*)lpb;
GetRawInputDeviceInfo(raw->header.hDevice, RIDI_PREPARSEDDATA, NULL, &dwSize);
PHIDP_PREPARSED_DATA preparsedData = (PHIDP_PREPARSED_DATA)HeapAlloc(GetProcessHeap(), 0, dwSize);
GetRawInputDeviceInfo(raw->header.hDevice, RIDI_PREPARSEDDATA, preparsedData, &dwSize);
HIDP_CAPS caps;
HidP_GetCaps(preparsedData, &caps);
USHORT capsLength = caps.NumberInputValueCaps;
PHIDP_VALUE_CAPS valueCaps = (PHIDP_VALUE_CAPS)HeapAlloc(GetProcessHeap(), 0, capsLength*sizeof(HIDP_VALUE_CAPS));
HidP_GetValueCaps(HidP_Input, valueCaps, &capsLength, preparsedData);
for (int i=0; i < capsLength; i++) {
CHAR value;
USHORT valuelength = valueCaps[i].BitSize * valueCaps[i].ReportCount;
HidP_GetUsageValueArray (HidP_Input, valueCaps[i].UsagePage, 0, valueCaps[i].NotRange.Usage, &value, valuelength, preparsedData, (PCHAR)raw->data.hid.bRawData, raw->data.hid.dwSizeHid);
std::cout << valueCaps[i].UsagePage << " " << valueCaps[i].NotRange.Usage <<std::endl;
std::cout << value << std::endl;
switch(valueCaps[i].NotRange.Usage) {
case 0x30: // X-axis
std::cout << "X: " << value << std::endl;
break;
case 0x31: // Y-axis
std::cout << "y: " << value << std::endl;
break;
}
}
}
Problem
I compiled the code and touch my touchpad, but all the outputs are:
0 0
³
Have I done anything wrong? Does anyone have any idea?