#include <iostream>
#include <conio.h>
using namespace std;
bool running = false;
int clickCount = 0;
void simulateClick()
{
INPUT input[2] = {0};
input[0].type = INPUT_MOUSE;
input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
input[1].type = INPUT_MOUSE;
input[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(2, input, sizeof(INPUT));
clickCount++;
}
DWORD WINAPI clickerThread(LPVOID lpParam)
{
const int delay = 10;//改变大小可以控制鼠标点击速度(越低越快,别设太低电脑cpu会烧)
while(running)
{
simulateClick();
Sleep(delay);
}
return 0;
}
int main()
{
cout << "Dev-C++ 鼠标连点器 (每秒30次)" << endl;
cout << "=============================" << endl;
cout << "按 F6 键 开始/停止连点" << endl;
cout << "按 ESC 键 退出程序" << endl;
cout << "=============================" << endl;
HANDLE hThread = NULL;
while(true)
{
if(GetAsyncKeyState(VK_F6) & 0x8000)
{
running = !running;
if(running)
{
clickCount = 0;
cout << "连点器已启动 (每秒30次点击)" << endl;
hThread = CreateThread(NULL, 0, clickerThread, NULL, 0, NULL);
}
else
{
cout << "连点器已停止" << endl;
cout << "本次共点击 " << clickCount << " 次" << endl;
}
Sleep(300);
}
if(GetAsyncKeyState(VK_ESCAPE) & 0x8000)
{
running = false;
if(hThread != NULL)
{
WaitForSingleObject(hThread, 100);
CloseHandle(hThread);
}
cout << "程序已退出" << endl;
break;
}
Sleep(10);
}
return 0;
}