Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么我不能从鼠标中检索输入数据?_C++_Winapi_Mouse_Raw Input - Fatal编程技术网

C++ 为什么我不能从鼠标中检索输入数据?

C++ 为什么我不能从鼠标中检索输入数据?,c++,winapi,mouse,raw-input,C++,Winapi,Mouse,Raw Input,我正在开发一个将鼠标输入转换为虚拟操纵杆的应用程序,我尝试过做低级鼠标输入,但获取鼠标位置是不够的,所以我使用了rawinput,但现在我卡住了,我无法从鼠标检索数据 int main(int argc, char** argv) { while (true) { printf("%d %d\n", mouse_x, mouse_y); Sleep(100); } } LRESULT CAL

我正在开发一个将鼠标输入转换为虚拟操纵杆的应用程序,我尝试过做低级鼠标输入,但获取鼠标位置是不够的,所以我使用了rawinput,但现在我卡住了,我无法从鼠标检索数据

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;
                }
        }
    }

看看这个问题和答案。。。[获取当前光标位置]()这可能会有帮助。。。您甚至可以在后台运行一个线程来继续捕获…发布的代码缺少按钮的提取和鼠标移动方向的计算(与以前的输入相比)。在使用它之前,您必须注册原始输入设备。使用RealStReWrWPIDsDebug来做SoC不是C++是不是C,而且你的窗口过程永远不会被调用,因为你没有注册那个窗口过程,而你使用的是主而不是Win。