title: How to get touch screen coordination from WM_INPUT raw data
body: <p>I have my touch screen monitor registered with RegisterRawInputDevices. When I tap with one finger, I receive many WM_INPUT event.</p>
  
  <p>How can I get readable data from WM_INPUT HID (touch) event (coordinations, type of touch)?</p>
  
  <pre><code>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,
                  &amp;data_size, sizeof(RAWINPUTHEADER));
              // preallocate our buffer
              vector&lt;BYTE&gt; data;
              data.resize(data_size);
              // and then read the input data in
              if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &amp;data[0],
                  &amp;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*)(&amp;data[0]);
              // make sure keyboard/mouse HID data didn't somehow sneak its way in here
              if (raw-&gt;header.dwType == RIM_TYPEHID)
              {
                  // for each packet received..
                  for (DWORD index(0); index &lt; raw-&gt;data.hid.dwCount; ++index)
                  {
                      mylog(".............HID packet .............");
                      // reinterpret the data as our nicely formatted digitizer-specific structure
                      DigitizerData* result((DigitizerData*)&amp;raw-&gt;data.hid.bRawData[raw-&gt;data.hid.dwSizeHid * index]);
                      // for each touch registered...
                      for (BYTE touch_index(0); touch_index &lt; result-&gt;active_touch_count; ++touch_index)
                      {
                          // insert touch handler code here
                          int touch_x(result-&gt;touch[touch_index].X());
                          int touch_y(result-&gt;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;
  }
  </code></pre>
  
  <p>Digitizer data and code is from <a href="https://www.codeproject.com/Articles/381673/Using-the-RawInput-API-to-Process-MultiTouch-Digit" rel="nofollow noreferrer">https://www.codeproject.com/Articles/381673/Using-the-RawInput-API-to-Process-MultiTouch-Digit</a> .</p>
  
  <p>Output of this code when one finger tap:</p>
  
  <p><a href="https://i.stack.imgur.com/kcgza.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kcgza.png" alt="enter image description here"></a></p>