Skip to content

Instantly share code, notes, and snippets.

@bruno-cadorette
Last active August 29, 2015 14:23
Show Gist options
  • Save bruno-cadorette/e1a96589948960c13c2e to your computer and use it in GitHub Desktop.
Save bruno-cadorette/e1a96589948960c13c2e to your computer and use it in GitHub Desktop.
Press S to start and X to stop
#include "Windows.h"
#include <iostream>
#include <thread>
using namespace std;
void WaitForKey(int vKey)
{
while (!GetAsyncKeyState(vKey));
}
void LeftClick()
{
INPUT Input;
// left down
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &Input, sizeof(INPUT));
// left up
ZeroMemory(&Input, sizeof(INPUT));
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &Input, sizeof(INPUT));
}
void Clicks(volatile bool& stop)
{
while (!stop)
{
LeftClick();
Sleep(10);
}
}
int main()
{
volatile bool stop;
while (true)
{
stop = false;
WaitForKey('S');
cout << "Start" << endl;
thread endTask([&stop] {
WaitForKey('X');
cout << "Stop" << endl;
stop = true;
});
Clicks(stop);
endTask.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment