0

I am building an app that will translate mouse input to virtual joystick, I have tried doing low level mouse input, but getting mouse position was not enough, so I went with rawinput, but now I am stuck, I cant retrieve data from mouse.

int main(int argc, char** argv)
    {
        while (true) {
            printf("%d %d\n", mouse_x, mouse_y);
            Sleep(100);
        }

    }
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
        switch (uMsg) {
                case WM_CREATE:
                    RAWINPUTDEVICE Rid[2];

                    Rid[0].usUsagePage = 0x01;
                    Rid[0].usUsage = 0x02;
                    Rid[0].dwFlags = RIDEV_INPUTSINK;   // adds HID mouse and also ignores legacy mouse messages
                    Rid[0].hwndTarget = 0;

                    Rid[1].usUsagePage = 0x01;
                    Rid[1].usUsage = 0x06;
                    Rid[1].dwFlags = RIDEV_INPUTSINK;   // adds HID keyboard and also ignores legacy keyboard messages
                    Rid[1].hwndTarget = 0;
                    return 0;
                case WM_INPUT:
                {
                    UINT dwSize;
                    GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
                    LPBYTE lpb = new BYTE[dwSize];
                    GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
                    RAWINPUT* raw = (RAWINPUT*)lpb;

                    if (raw->header.dwType == RIM_TYPEKEYBOARD)
                    {
                    }
                    else if (raw->header.dwType == RIM_TYPEMOUSE)
                    {
                        mouse_x = raw->data.mouse.lLastX;
                        mouse_y = raw->data.mouse.lLastY;
                    }
                    delete[] lpb;
                    break;
                }
        }
    }
Stargateur
  • 24,473
  • 8
  • 65
  • 91
R1per
  • 1
  • Have a look at this question and answer... [Get current cursor position ](https://stackoverflow.com/questions/6423729/get-current-cursor-position) It might help... You can have even a thread running in the background to keep capturing... – TooGeeky Jul 05 '17 at 21:05
  • the posted code is missing the extraction of the buttons and the calculation (compared to prior input) of the mouse direction of movement,. – user3629249 Jul 06 '17 at 01:58
  • 1
    You have to register your raw input devices before using it. Use RegisterRawInputDevices to do so – Asesh Jul 06 '17 at 03:20
  • C is not C++ is not C. – Stargateur Jul 06 '17 at 06:32
  • Besides your window procedure would never be called because you have not registered that window procedure and you are using main instead of WinMain. – Asesh Jul 06 '17 at 06:58

0 Answers0