C++不存在从输入到LPINPUT的合适转换功能

发布于 2025-01-26 05:21:13 字数 635 浏览 2 评论 0原文

我正在尝试获取鼠标的坐标,然后将鼠标相对移动到这些坐标。

#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

int main() {
    SHORT f5;
    POINT pt{};
    MOUSEINPUT _mi{};
    INPUT mm{};
    mm.type = 0;
    for (;;) {
        f5 = GetAsyncKeyState(0x74);
        if (f5 > 0) {
            GetCursorPos(&pt);
            _mi.dx = pt.x + 100;
            _mi.dy = pt.y + 100;
            mm.mi = _mi;
            SendInput(1, mm, sizeof(mm));   
        }
        Sleep(50);
    }
    return 0;
}

我遇到了一个错误,说不存在从输入到LPINPUT的合适转换,但我也不知道如何创建“ LPINPUT”结构。

i'm trying to get the coordinates of the mouse, then move the mouse relative to those coordinates.

#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

int main() {
    SHORT f5;
    POINT pt{};
    MOUSEINPUT _mi{};
    INPUT mm{};
    mm.type = 0;
    for (;;) {
        f5 = GetAsyncKeyState(0x74);
        if (f5 > 0) {
            GetCursorPos(&pt);
            _mi.dx = pt.x + 100;
            _mi.dy = pt.y + 100;
            mm.mi = _mi;
            SendInput(1, mm, sizeof(mm));   
        }
        Sleep(50);
    }
    return 0;
}

I'm getting an error saying that no suitable conversion from INPUT to LPINPUT exists, but I also have no idea how to create a "LPINPUT" struct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2025-02-02 05:21:13

sendInput()期望指向Input结构的数组。由于您仅传递1 输入,请将其作为指针的地址作为指针,通过将结构与>&amp;运算符相结合,只需就像getCursorPos()一样:

SendInput(1, &mm, sizeof(mm));

SendInput() expects a pointer to an array of INPUT structures. Since you are passing only 1 INPUT, give it the address of your INPUT as a pointer by prefixing the structure with the & operator, just as you did with GetCursorPos():

SendInput(1, &mm, sizeof(mm));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文