"mouse_event"函数 - 将光标发送到(稍微)错误的坐标
"mouse_event" function - sending cursor to (slightly) wrong coordinates
mouse_event函数将光标发送到稍微错误的坐标(偏离1-20像素)。它"偏离"的程度是基于一种我不太清楚的模式。
我的代码
int x, y;
int repeats = 1000;
int start = 0;
POINT pt;
for(int i=0; i<repeats; i+=10) //first loop, down right
{
x = (65536 / 1920) * i - 1; //convert to absolute coordinates
y = (65536 / 1080) * i - 1;
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0); //move
GetCursorPos(&pt); //get cursor position
if(pt.x != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);} //check if the position is wrong, and if so fix it.
if(pt.y != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);}
cout << "Try: " << i << ", " << i << "tReal: " << pt.x << ", " << pt.y << "tDiff: " << pt.x - i << ", " << pt.y - i << 'n';
}
for(int i=repeats; i>0; i-=10) //second loop, up left
{
x = (65536 / 1920) * i - 1;
y = (65536 / 1080) * i - 1;
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
GetCursorPos(&pt);
if(pt.x != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);}
if(pt.y != i){mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);}
cout << "Try: " << i << ", " << i << "tReal: " << pt.x << ", " << pt.y << "tDiff: " << pt.x - i << ", " << pt.y - i << 'n';
}
如果运行此命令,将导致鼠标从屏幕左上角向下和向右移动,然后再向上移动。但越往下,"mouse_event"创建的鼠标移动就越不正确。
我移动它,然后记录当前坐标,然后计算差值。这种差异(移动误差)随着我在屏幕上的移动而增加。我甚至尝试添加一个额外的检查,测试如果坐标是关闭的,然后尝试将鼠标移动到正确的位置,但它不工作知道为什么会这样吗?
为方便起见,这里是该程序输出的日志。
Output_Log.txt
它清楚地表明,在第一个循环(向下和向右移动鼠标)中,错误增加,然后在第二个循环(再次向上和向左移动鼠标)中,错误以同样的方式减少。
知道为什么会这样吗?它发生在更复杂的实现以及我无法量化的方式,不像这个,所以我认为它必须在mouse_event函数本身或一些我不理解的功能
提前感谢您的帮助
我想说这是由于使用整数算法来计算像素,试试这个:
x = (int)(65536.0 / 1920 * i - 1); //convert to absolute coordinates
y = (int)(65536.0 / 1080 * i - 1);
相关文章:
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- OpenGL 4.3 错误地将第 4 个纹理坐标映射到与第 3 个纹理坐标相同的位置
- 比较两个节点坐标的最佳方法是什么?
- 在 OpenGL 中将笛卡尔世界坐标转换为球面局部坐标
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- 如何在C++中获取坐标?
- 如何将 x.y 坐标的值存储在不同的数组中
- 试图(稍微)概括C++模板.关联容器键:值反转
- 如何将鼠标坐标转换为"mm"
- 重心坐标并不总是有效(3d)
- 尝试渲染像素坐标时,简单线条渲染失败
- 使用 GTK3 C++获取指针坐标
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 我想制作设置鼠标回调函数,以便在仍然按下鼠标左键时连续传递坐标
- 将鼠标悬停在图片框上时,如何显示带有 x-y 坐标的十字准线光标?
- 跳转到通过输入坐标定义的控制台屏幕位置
- QImage::p ixel 和 QImage::setPixel 坐标超出范围误差
- "mouse_event"函数 - 将光标发送到(稍微)错误的坐标