Repository navigation
Expand file tree
/
Copy pathJklmBotAuto.cpp
More file actions
294 lines (252 loc) · 6.87 KB
/
Copy pathJklmBotAuto.cpp
File metadata and controls
294 lines (252 loc) · 6.87 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <regex>
#include <utility>
#include <windows.h>
using namespace std;
std::string browse(HWND hwnd)
{
std::string path(MAX_PATH, '\0');
OPENFILENAME ofn = { sizeof(OPENFILENAME) };
ofn.hwndOwner = hwnd;
ofn.lpstrFilter =
"Text files (*.txt)\0*.txt\0"
"All files\0*.*\0";
ofn.lpstrFile = &path[0];
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn))
{
path.resize(strlen(path.c_str()));
}
return path;
}
void writeWord(std::string _word) {
//print the string with the keyboard
for (int i = 0; i < _word.length(); i++) {
keybd_event((BYTE)VkKeyScan(_word[i]), 0, 0, 0);
keybd_event((BYTE)VkKeyScan(_word[i]), 0, KEYEVENTF_KEYUP, 0);
//delay between each letter
Sleep(30);
}
//Hit enter
keybd_event((BYTE)VkKeyScan('\r'), 0, 0, 0);
keybd_event((BYTE)VkKeyScan('\r'), 0, KEYEVENTF_KEYUP, 0);
}
//make a function that returns the color of the pixel at the given coordinates
COLORREF getPixelColor(int x, int y) {
HDC hdc = GetDC(NULL);
COLORREF color = GetPixel(hdc, x, y);
ReleaseDC(NULL, hdc);
return color;
}
int main()
{
vector<string> words;
vector<string> usedwords;
string filename;
cout << "CHOOSE A DICTIONARY..." << endl;
filename = browse(0);
std::replace(filename.begin(), filename.end(), '\\', '/');
if (filename.size() == 0) {
cout << "Error opening path. Exiting" << endl;
exit(1);
}
cout << "Dictionary Selected:" << filename << endl << endl;
ifstream file(filename);
string line;
if (file.fail()) {
cout << "Error opening file. Exiting" << endl;
exit(2);
}
while (!file.eof())
{
getline(file, line);
words.push_back(line);
}
file.close();
//Short the vector by length the longest word first
sort(words.begin(), words.end(), [](const string& a, const string& b) {
return a.size() < b.size();
});
std::pair<int, int> mousePos;
std::pair<int, int> mousePoslast;
std::pair<int, int> mousePosColor = { 0, 0 };
bool mouseNoSelected = true;
bool mouseNoSelectedColor = true;
LPPOINT lpPoint = new tagPOINT;
HANDLE hData;
string text;
COLORREF color;
bool onetime = true;
bool downCtrl = false;
bool downAlt = false;
bool downShift = false;
bool releasedCtrl = false;
bool releasedAlt = false;
bool releasedShift = false;
bool myturn = false;
cout << "READY" << endl;
while (onetime)
{
//If the Ctrl key is released
if (GetAsyncKeyState(VK_CONTROL) < 0)
{
if (!downCtrl) {
downCtrl = true;
}
}
else
{
if (downCtrl)
{
downCtrl = false;
//Released
releasedCtrl = true;
}
}
//If the Alt key is released
if (GetAsyncKeyState(VK_MENU) < 0)
{
if (!downAlt) {
downAlt = true;
}
}
else
{
if (downAlt)
{
downAlt = false;
//Released
releasedAlt = true;
}
}
//If the Shift key is released
if (GetAsyncKeyState(VK_SHIFT) < 0)
{
if (!downShift) {
downShift = true;
}
}
else
{
if (downShift)
{
downShift = false;
//Released
releasedShift = true;
}
}
if (releasedShift) {
onetime = false;
}
if (releasedAlt)
{
GetCursorPos(lpPoint);
mousePos.first = lpPoint->x;
mousePos.second = lpPoint->y;
mouseNoSelected = false;
releasedAlt = false;
cout << "Letters X: " << mousePos.first << " Letters Y: " << mousePos.second << endl;
}
if (releasedCtrl) {
//Set the mousePosColor to the current mouse position
GetCursorPos(lpPoint);
mousePosColor.first = lpPoint->x;
mousePosColor.second = lpPoint->y;
mouseNoSelectedColor = false;
releasedCtrl = false;
cout << "Color X: " << mousePosColor.first << " Color Y: " << mousePosColor.second << endl;
}
//Get the color of the pixel at the mouse position
color = getPixelColor(mousePosColor.first, mousePosColor.second);
//If the color is yellow (R and G are more than 200)
if (GetRValue(color) >= 180 && GetGValue(color) >= 180) {
myturn = true;
cout << "MY TURN" << endl;
}
else {
myturn = false;
}
//Set delay
Sleep(100);
//When the ctrl is released
if (myturn && !mouseNoSelected && !mouseNoSelectedColor)
{
//Get current mouse position
GetCursorPos(lpPoint);
mousePoslast.first = lpPoint->x;
mousePoslast.second = lpPoint->y;
//Move the mouse to the position
SetCursorPos(mousePos.first, mousePos.second);
//Double click on the mouse position
mouse_event(MOUSEEVENTF_LEFTDOWN, mousePos.first, mousePos.second, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, mousePos.first, mousePos.second, 0, 0);
Sleep(20);
mouse_event(MOUSEEVENTF_LEFTDOWN, mousePos.first, mousePos.second, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, mousePos.first, mousePos.second, 0, 0);
//Make Ctrl+C
keybd_event(VK_CONTROL, 0x9d, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(0x43, 0x9d, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(0x43, 0x9d, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0x9d, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
Sleep(75);
//Go back to the last position
SetCursorPos(mousePoslast.first, mousePoslast.second);
//Click on the mouse position
mouse_event(MOUSEEVENTF_LEFTDOWN, mousePoslast.first, mousePoslast.second, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, mousePoslast.first, mousePoslast.second, 0, 0);
if (!OpenClipboard(NULL)) {
std::cout << "Error opening clipboard" << std::endl;
CloseClipboard();
return false;
}
//Get the text from the clipboard
hData = GetClipboardData(CF_TEXT);
if (hData == NULL) {
std::cout << "Error getting clipboard data" << std::endl;
CloseClipboard();
return false;
}
//Close clipboard
CloseClipboard();
//Save the text in a string
text = (char*)hData;
//To upper case
std::transform(text.begin(), text.end(), text.begin(), ::toupper);
myturn = false;
//If the text isnt empty
if (text.size() > 0) {
cout << "Text: " << text << endl;
//Search in the dictionary the word that contains the text
int i = 0;
bool found = false;
while (i < words.size() && !found) {
if (words[i].find(text) != std::string::npos) {
cout << "Word found: " << words[i] << endl;
//If the word is found and doesnt exist on the usadas vector, write it
int k = 0;
int found_used = false;
while (k < usedwords.size() && !found_used) {
if (usedwords[k] == words[i]) {
found_used = true;
}
k++;
}
if (!found_used) {
writeWord(words[i]);
found = true;
usedwords.push_back(words[i]);
}
}
i++;
}
}
}
}
//free lpPoint
delete lpPoint;
return 0;
}