嗨,大家好我正在編寫一個程序,在循環中爲我做幾個鼠標點擊。我創建了一個結構並將其設置爲鍵入INPUT_MOUSE以複製點擊並使用SendInput()發送信息。一切都編譯正確,可以稱爲「工作」計劃,但我遇到了一個相當有趣的故障。我在我的筆記本電腦上寫了這個程序(windows vista)試過了,它運行的很好。當我重寫相同的確切代碼並在我的桌面(Windows 7)上使用它時,當我運行該程序時,只要我啓動程序的自動化部分,就像進入睡眠模式時一樣,屏幕將變黑。該程序將在後臺運行,但它的automater黑色我的屏幕的痛苦。任何想法這裏發生了什麼?如果需要,我可以顯示代碼。提前致謝。自動鼠標點擊使屏幕變爲空白
的要求林加入我的代碼
enter code here
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
void clicky(int x, int y)
{
// 5 sec wait
clock_t run;
run = clock()+5*CLOCKS_PER_SEC;
while (clock() < run) {}
//plug in cursor coords and click down and up
SetCursorPos(x,y);
INPUT mouse;
mouse.type = INPUT_MOUSE;
mouse.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1,&mouse,sizeof(INPUT));
mouse.type = INPUT_MOUSE;
mouse.mi.dwFlags= MOUSEEVENTF_LEFTUP;
SendInput(1,&mouse,sizeof(INPUT));
}
void main()
{
int coords=0;
string h;
//find out how many clicks are needed
cout << "How many clicks will you need?";
cin >> coords;
//extra getline here without it when return is hit
//from entering the click amount it would also enter
//a cursor coordinate
getline(cin,h);
POINT p[21];
for (int count = 1;count<=coords;count++)
{
cout << "Place mouse cursor where you want a click and press return"<<endl;
//each time return is hit the cursor coordinates
//will be stored in the corresponding spot in
// the p array
string key = "r";
getline(cin,key);
GetCursorPos(&p[count]);
break;
}
string go;
cout << "Hit Return to initialize your click loop";
getline(cin,go);
while (true)
//infinite loop cycling through the users
//cursor coordinates and clicking
{
for(int click=1;click<=coords;click++)
{
int x = p[click].x;
int y = p[click].y;
clicky(x,y);
}
}
}
是的,我們將需要看到一些代碼 – 2011-03-22 17:38:30