c++ - winapi mouse_event 错误坐标

标签 c++ winapi mouseevent

我尝试制作一个 autoClicker 来记录我放置鼠标的位置,然后点击精确协调的位置,但最后它在我的鼠标最后一个位置上点击的次数相同。

const int WAIT_INTERVAL = 5;
const int CLICK_POINTS = 5;
POINT mouse[CLICK_POINTS];
int clicks;
bool didGetPos;

for (int i = 1; i <= CLICK_POINTS; i++)
    {
        cout << i << " spot" << endl;
        Sleep(3000);
        didGetPos = GetCursorPos(&mouse[i - 1]);

        if (!didGetPos)
        {
            break;
        }
    }

    if (didGetPos)
    {
        for (int i = 0; i < CLICK_POINTS; i++)
        {
            for (int j = 0; j < clicks; j++)
            {
                mouse_event(MOUSEEVENTF_LEFTDOWN, mouse[i].x, mouse[i].y, 0, 0);
                mouse_event(MOUSEEVENTF_LEFTUP, mouse[i].x, mouse[i].y, 0, 0);
            }
        }
    }

最佳答案

您没有包含 MOUSEEVENTF_ABSOLUTE 标志。 documentation说:

The dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system.

您传递的是绝对坐标,因此需要包含 MOUSEEVENTF_ABSOLUTE 标志。

当然,您应该注意文档并停止使用这个被取代的函数。使用 SendInput

关于c++ - winapi mouse_event 错误坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36163925/

相关文章:

delphi - 即使菜单项未启用,也可以接收 OnClick 事件吗?

javascript - 如何创建一个 Shift 键 + 鼠标单击事件,单击时将黑色按钮的颜色更改为黄色按钮? JavaScript

javascript - 设置 useMap 后无法更改图像源

c++ - QGroupBox 的 children().count() 返回值超过预期

c++ - 如何限制在 VS 设计器中创建的编辑框中的数字

c++ - 使用多线程获得连续的蜂鸣声

c++ - SetConsoleMode 标志中 ENABLE_PROCESSED_INPUT 的含义

c++ - 原子写入后跟同一个变量的原子读取的屏障有多有效?

C++ 映射 : Smart algorithm needed

c++ - 为什么在取消引用 std::set<T>::iterator 时需要 const?