我尝试制作一个 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/