Как получить координацию сенсорного экрана из исходных данных WM_INPUT - PullRequest
0 голосов
/ 26 февраля 2019

Мой монитор с сенсорным экраном зарегистрирован в 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.

Вывод этого кода при нажатии одним пальцем:

enter image description here

...