[英]winapi mouse_event wrong coords
I tried to make an autoClicker that record where I put my mouse and then click the exact coordinated but in the end it clicks the same number of clicks on the last spot that my mouse was. 我试图制作一个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);
}
}
}
You did not include the MOUSEEVENTF_ABSOLUTE
flag. 您没有包含
MOUSEEVENTF_ABSOLUTE
标志。 The documentation says: 该文件说:
The dx and dy parameters contain normalized absolute coordinates.
dx和dy参数包含标准化的绝对坐标。 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.
无论将哪种鼠标或类似鼠标的设备连接到系统,都可以设置或不设置此标志。
You are passing absolute coordinates and so need to include the MOUSEEVENTF_ABSOLUTE
flag. 您正在传递绝对坐标,因此需要包含
MOUSEEVENTF_ABSOLUTE
标志。
Of course you should heed the documentation and stop using this superseded function. 当然,您应该注意文档并停止使用此已取代的功能。 Use
SendInput
. 使用
SendInput
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.