//init
RAWINPUTDEVICE Rid = {};
Rid.usUsagePage = HID_USAGE_PAGE_GENERIC;
Rid.usUsage = HID_USAGE_GENERIC_MOUSE;
Rid.dwFlags = 0;
Rid.hwndTarget = 0; //hWnd window
if (!RegisterRawInputDevices(&Rid, 1, sizeof(RAWINPUTDEVICE)))
std::cout << "Device Registration failed" << std::endl;
else
std::cout << "Device Registration successful" << std::endl;
// LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (uMsg == WM_INPUT) { //вызывается перед событиями мышки вроде WM_LBUTTON
UINT dwSize;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize];
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
std::cout << "GetRawInputData does not return correct size !" << std::endl;
RAWINPUT *raw = (RAWINPUT *)lpb;
if (raw->header.dwType == RIM_TYPEMOUSE)
{
//raw->header.hDevice - handle мышки которая сделала нажатие
}
delete[] lpb;
}