#include <windows.h>
#include <bits/stdc++.h>
#include <atomic>
#include <thread>
using namespace std;
atomic<bool> g_running(0);
const int THREAD_COUNT = 100; // 线程数量
void ClickerThread(int threadId)
{
while (g_running)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(10);
Sleep(threadId * 2);
}
}
int main()
{
vector<thread> threads;
system("color a");
cout << "多线程连点器 - 按住Ctrl键开始/停止连点" << endl;
cout << "使用 " << THREAD_COUNT << " 个线程" << endl;
cout << R"(
提示:
1.线程数不要超100,超过电脑范围电脑会自动限制你的线程数,再大很多(比如1万)电脑直接就崩溃了(本人不负责哈)
2.线程数去代码里改
3.!!!>>>>>>>> 最重要的:用c++14编译!<<<<<<<<<<<<<!!!!!)";
while (true)
{
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
g_running = !g_running;
if (g_running)
{
cout << "连点器启动" << endl;
for (int i = 0; i < THREAD_COUNT; ++i)
{
threads.emplace_back(ClickerThread, i);
}
}
else
{
cout << "连点器停止" << endl;
for (auto& thread : threads)
{
if (thread.joinable())
{
thread.join();
}
}
threads.clear();
}
Sleep(300);
}
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
{
g_running = false;
for (auto& thread : threads)
{
if (thread.joinable())
{
thread.join();
}
}
break;
}
Sleep(10);
}
return 0;
}
1 个赞