我需要自動化一些鼠標動作。如何自動化鼠標動作
我需要做的
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