Last active
August 29, 2015 14:23
-
-
Save bruno-cadorette/e1a96589948960c13c2e to your computer and use it in GitHub Desktop.
Press S to start and X to stop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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