c++ - 如何从 WM_INPUT 原始数据中获取触摸屏协调
问题描述
我在 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。
一根手指点击时此代码的输出:
解决方案
推荐阅读
- vue.js - XState 不会停留在空闲状态
- selenium - 如何在谷歌 colab 中运行 chrome webdriver?
- php - 我可以通过 POST PHP 传递一个名称 + 一个 var
- algorithm - 查找图中的边数的算法,其中顶点由集合定义
- python - 通过运行 open 或其他任何方式创建文件,我们可以用密码保护它吗
- telegram - 有没有办法在电报组描述文本中添加超链接?
- c# - 使用 AMQP 协议时,如何在 Azure 中识别从设备到 IoT 中心的消息大小?
- tiddlywiki - 当您将图像嵌入时,如何避免 Stroll 或 TiddlyWiki 将图像列为孤儿?
- .net - 使用 dotnet-trace 获取内存时为空 Speedscope 文件
- graphql - 如何在 graphQl/Sequelize 中的嵌套查询上应用 where 子句?