-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
193 lines (139 loc) · 3.72 KB
/
Source.cpp
File metadata and controls
193 lines (139 loc) · 3.72 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <iostream>
#include <windows.h>
bool clicking;
POINT point;
DWORD Milliseconds;
WORD Virtualkey;
HANDLE hStdin;
DWORD fdwSaveOldMode;
void KeyEventProc(KEY_EVENT_RECORD);
void setTimer() {
std::cout << "type how many milliseconds you want the auto clicker to rest between clicks?" << std::endl;
std::cin >> Milliseconds;
}
void mouse_clicker() {
clicking = true;
SetCursorPos(point.x, point.y);
setTimer();
while (true)
{
INPUT ip;
ip.type = INPUT_MOUSE;
ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &ip, sizeof(INPUT));
ZeroMemory(&ip, sizeof(INPUT));
ip.type = INPUT_MOUSE;
ip.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &ip, sizeof(INPUT));
if (GetAsyncKeyState(VK_NUMPAD1)) {
clicking = false;
break;
}
Sleep(Milliseconds);
}
}
int GetpressedKey() {
// ref : https://docs.microsoft.com/en-us/windows/console/reading-input-buffer-events
DWORD cNumRead, fdwMode, i;
INPUT_RECORD irInBuf[128]; // i think i need to lower this value cuz its too big what do you think?
int counter = 0;
// Get the standard input handle.
hStdin = GetStdHandle(STD_INPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE)
std::cout << "getstdhandle" << std::endl;
// Save the current input mode, to be restored on exit.
if (!GetConsoleMode(hStdin, &fdwSaveOldMode))
return 0;
// Enable the window and mouse input events.
fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
if (!SetConsoleMode(hStdin, fdwMode))
return 0;
// Loop to read and handle the next 1 and only input event.
std::cout << "Press a key you want to get auto pressed" << std::endl;
while (counter++ <= 1)
{
// Wait for the events.
if (!ReadConsoleInput(
hStdin, // input buffer handle
irInBuf, // buffer to read into
128, // size of read buffer
&cNumRead)) // number of records read
return 0;
// Dispatch the events to the appropriate handler.
for (i = 0; i < cNumRead; i++)
{
switch (irInBuf[i].EventType)
{
case KEY_EVENT: // keyboard input
KeyEventProc(irInBuf[i].Event.KeyEvent);
break;
default:
break;
}
}
}
}
void KeyEventProc(KEY_EVENT_RECORD ker)
{
if (ker.bKeyDown)
Virtualkey = ker.wVirtualKeyCode;
}
void keyboard_clicker() {
clicking = true;
setTimer();
GetpressedKey();
while (true) {
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = Virtualkey;
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
// Release key
ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
if (GetAsyncKeyState(VK_NUMPAD3)) {
clicking = false;
break;
}
Sleep(Milliseconds);
}
}
void StartClicker() {
while (true)
{
if (GetAsyncKeyState(VK_HOME)) {
// capture mosue postion
GetCursorPos(&point);
}
if (GetAsyncKeyState(VK_DELETE)) {
// exit program
break;
}
if (GetAsyncKeyState(VK_NUMPAD0)) {
// start mouse clicking here in a while loop
mouse_clicker();
}
if (GetAsyncKeyState(VK_NUMPAD2)) {
// keyboard clicking.
keyboard_clicker();
}
Sleep(300);
}
}
void printConsoleMenu() {
clicking = false;
// print stuff to the user
std::cout << "[+] press [Home key] to capture mouse postion" << std::endl;
std::cout << "[+] press [Delete key] to exit the program!" << std::endl;
std::cout << "[+] press [Numpad 0] to start [mouse]autoclicker" << std::endl;
std::cout << "[+] press [Numpad 1] to stop [mouse]autoclicker" << std::endl;
std::cout << "[+] press [Numpad 2] to start [keyboard]autoclicker" << std::endl;
std::cout << "[+] press [Numpad 3] to stop [keyboard]autoclicker" << std::endl;
StartClicker();
}
int main() {
printConsoleMenu();
}