-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathauto_clicker.cpp
62 lines (49 loc) · 2.25 KB
/
auto_clicker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <macro/macro.h>
#include <iostream>
#include <thread>
bool buttonCallback(Macro::Mouse::Button button, Macro::Mouse::ButtonState state) {
// Block X1 and X2 button presses.
return (button == Macro::Mouse::Button::X1 || button == Macro::Mouse::Button::X2);
}
int main() {
std::cout << "Starting auto clicker..." << std::endl;
// Register our button callback.
Macro::Mouse::SetButtonCallback(buttonCallback);
std::cout << "Registered button callback." << std::endl;
// Start the mouse hook in a separate thread so it doesn't block our main loop.
std::thread(Macro::Mouse::MouseHookLoop).detach();
std::cout << "Mouse hook started." << std::endl;
std::cout << "Hold the X1 mouse button down to temporarily enable the left auto clicker.\n"
<< "Hold the X2 mouse button down to temporarily enable the right auto clicker.\n"
<< "Press Ctrl+C to exit." << std::endl;
while (true) {
// Get the current X1 and X2 mouse button states and store them in variables.
// This is to ensure that the clicker releases the button even if the user releases their
// X1 or X2 mouse button.
bool x1Pressed = Macro::Mouse::GetButtonState(Macro::Mouse::Button::X1) ==
Macro::Mouse::ButtonState::DOWN;
bool x2Pressed = Macro::Mouse::GetButtonState(Macro::Mouse::Button::X2) ==
Macro::Mouse::ButtonState::DOWN;
if (x1Pressed) {
// Press the left mouse button.
Macro::Mouse::Down(Macro::Mouse::Button::LEFT);
}
if (x2Pressed) {
// Press the right mouse button.
Macro::Mouse::Down(Macro::Mouse::Button::RIGHT);
}
// Hold the mouse buttons down for 20 milliseconds.
// We are using Sleep instead of PreciseSleep because we don't need the precision.
Macro::Misc::Sleep(20);
if (x1Pressed) {
// Release the left mouse button.
Macro::Mouse::Up(Macro::Mouse::Button::LEFT);
}
if (x2Pressed) {
// Release the right mouse button.
Macro::Mouse::Up(Macro::Mouse::Button::RIGHT);
}
// Wait 20 milliseconds before clicking again.
Macro::Misc::Sleep(20);
}
}