Repository navigation
Expand file tree
/
Copy pathJklmBotManual.cpp
More file actions
253 lines (219 loc) · 5.77 KB
/
Copy pathJklmBotManual.cpp
File metadata and controls
253 lines (219 loc) · 5.77 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
#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
}
//Hit enter
keybd_event((BYTE)VkKeyScan('\r'), 0, 0, 0);
keybd_event((BYTE)VkKeyScan('\r'), 0, KEYEVENTF_KEYUP, 0);
}
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
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;
bool mouseNoSelected = true;
LPPOINT lpPoint = new tagPOINT;
HANDLE hData;
string text;
bool onetime = true;
bool downCtrl = false;
bool downAlt = false;
bool downShift = false;
bool releasedCtrl = false;
bool releasedAlt = false;
bool releasedShift = 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;
cout << "X: " << mousePos.first << " Y: " << mousePos.second << endl;
mouseNoSelected = false;
releasedAlt = false;
}
//When the ctrl is released
if (releasedCtrl && !mouseNoSelected)
{
//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);
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(50);
//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);
Sleep(50);
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);
releasedCtrl = 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;
}