我的触摸屏显示器已向RegisterRawInputDevices注册。当我用一根手指轻击时,会收到许多WM_INPUT事件。
如何从WM_INPUT HID(触摸)事件(坐标,触摸类型)中获取可读数据?
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_INPUT:
do
{
// determine the size of the input data
UINT data_size(0);
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
&data_size, sizeof(RAWINPUTHEADER));
// preallocate our buffer
vector<BYTE> data;
data.resize(data_size);
// and then read the input data in
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &data[0],
&data_size, sizeof(RAWINPUTHEADER)) != data_size)
{
// handle the error gracefully
mylog("ERROR");
break;
}
// the RAWINPUT structure starts at the beginning of our data array
RAWINPUT* raw = (RAWINPUT*)(&data[0]);
// make sure keyboard/mouse HID data didn't somehow sneak its way in here
if (raw->header.dwType == RIM_TYPEHID)
{
// for each packet received..
for (DWORD index(0); index < raw->data.hid.dwCount; ++index)
{
mylog(".............HID packet .............");
// reinterpret the data as our nicely formatted digitizer-specific structure
DigitizerData* result((DigitizerData*)&raw->data.hid.bRawData[raw->data.hid.dwSizeHid * index]);
// for each touch registered...
for (BYTE touch_index(0); touch_index < result->active_touch_count; ++touch_index)
{
// insert touch handler code here
int touch_x(result->touch[touch_index].X());
int touch_y(result->touch[touch_index].Y());
mylog(string("Touch point ") + std::to_string(touch_x) + string(" x ") + std::to_string(touch_y));
}
}
}
} while (0);
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
}
数字化仪数据和代码来自https://www.codeproject.com/Articles/381673/Using-the-RawInput-API-to-Process-MultiTouch-Digit。
用一根手指点击时输出此代码: