我需要自动化一些鼠标动作。如何自动化鼠标动作
我需要做的
mousemove1,lbuttondown1,WAIT1,mousemove1,lbuttonup1,WAIT1,
mousemove2,lbuttondown2,WAIT2,mousemove2,lbuttonup2,WAIT2,
...
的操作必须关于屏幕坐标。必须接受事件的窗口是此时的顶层窗口。
有一个包含数据的文件。
例如
500 450 1000 500 300 2000
600 450 1000 600 300 5000
我是怎么尝试做
#include <fstream>
#include <vector>
#include <windows.h>
struct A
{
POINT point1;
unsigned sleep1;
POINT point2;
unsigned sleep2;
A() { point1.x = point1.y = sleep1 = point2.x = point2.y = sleep2 = 0; }
};
void f(const A &a)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, a.point1.x, a.point1.y, 0, 0);
mouse_event(MOUSEEVENTF_MOVE, a.point1.x, a.point1.y, 0, 0);
Sleep(a.sleep1);
mouse_event(MOUSEEVENTF_LEFTUP, a.point2.x, a.point2.y, 0, 0);
mouse_event(MOUSEEVENTF_MOVE, a.point2.x, a.point2.y, 0, 0);
Sleep(a.sleep2);
}
int main()
{
std::vector<A> as;
std::ifstream fin("params.txt");
if (fin) {
A a;
while (fin.good()) {
fin >> a.point1.x;
fin >> a.point1.y;
fin >> a.sleep1;
fin >> a.point2.x;
fin >> a.point2.y;
fin >> a.sleep2;
if (fin.eof()) {
break;
}
as.push_back(a);
}
}
for (;;) {
for (const A &a : as) {
f(a);
}
}
}
又出事了,但我不明白是什么在哪里是一个错误。
为什么不使用自动化? – 2015-02-08 13:25:53