Repository navigation
Expand file tree
/
Copy pathRobot.hpp
More file actions
289 lines (244 loc) · 7.78 KB
/
Copy pathRobot.hpp
File metadata and controls
289 lines (244 loc) · 7.78 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
#pragma once
#include <Windows.h>
#include "Pixel.hpp"
class Robot
{
private:
//for mouse and keybord simulation using SendInput()
static INPUT mouseInput;
static INPUT keyboardInput;
//for screen capturing using BitBlt()
HDC hdc; // get the desktop device context
HDC cdc; // create a device context to use yourself
int _height; // get the width and height of the screen
int _width; // only capture left monitor for dual screen setups, for both screens use (int)GetSystemMetrics(SM_CXVIRTUALSCREEN);
HBITMAP hbitmap; // create a bitmap
BITMAPINFOHEADER bmi;
RGBQUAD* screen;
UINT initializeMembers();
/**
* @brief Get scancode from char
*
* @param char keyStroke translated to scancode
* @return WORD scancode
*/
static WORD getScancode(char keyStroke);
/**
* @brief int to WORD for specific fKey
*
* @param fKey int representing f1 - f12
*/
static WORD getFKey(int fKey);
public:
Robot();
~Robot();
// Mouse
/**
* @brief Set the Cursor to a Position
*
* @param p position of the cursor after set
* @return BOOL success or failure
*/
UINT setCursorPos(const POINT& p) const;
/**
* @brief Moves and Presses the Left Mouse Button
*
* @param p position of the cursor for the press
* @return UINT error code
*/
UINT leftDown(const POINT& p) const;
/**
* @brief Presses the Left Mouse Button
*
* @return UINT error code
*/
UINT leftDown() const;
/**
* @brief Moves and Releases the Left Mouse Button
*
* @param p position of the cursor for the release
* @return UINT error code
*/
UINT leftUp(const POINT& p) const;
/**
* @brief Releases the Left Mouse Button
*
* @return UINT error code
*/
UINT leftUp() const;
/**
* @brief Moves and Presses the Right Mouse Button
*
* @param p position of the cursor for the press
* @return UINT error code
*/
UINT rightDown(const POINT& p) const;
/**
* @brief Presses the Right Mouse Button
*
* @return UINT error code
*/
UINT rightDown() const;
/**
* @brief Moves and Releases the Right Mouse Button
*
* @param p position of the cursor for the release
* @return UINT error code
*/
UINT rightUp(const POINT& p) const;
/**
* @brief Releases the Right Mouse Button
*
* @return UINT error code
*/
UINT rightUp() const;
/**
* @brief Moves and Clicks the Left Mouse Button
*
* @param p position of the cursor for the click
* @param clickDuration milliseconds
* @return UINT error code
*/
UINT leftClick(const POINT& p, DWORD clickDuration = 0) const;
/**
* @brief Clicks the Left Mouse Button
*
* @param clickDuration milliseconds
* @return UINT error code
*/
UINT leftClick(DWORD clickDuration = 0) const;
/**
* @brief Moves and Clicks the Right Mouse Button
*
* @param p position of the cursor for the click
* @param clickDuration milliseconds
* @return UINT error code
*/
UINT rightClick(const POINT& p, DWORD clickDuration = 0) const;
/**
* @brief Clicks the Right Mouse Button
*
* @param clickDuration milliseconds
* @return UINT error code
*/
UINT rightClick(DWORD clickDuration = 0) const;
// Keyboard
/**
* @brief Presses down the last key set
*/
UINT keyDown() const;
/**
* @brief Presses the provided key
*
* @param keyStroke character representing the key to press
*/
UINT keyDown(char keyStroke) const;
/**
* @brief Releases the last key set
*/
UINT keyUp() const;
/**
* @brief Releases the provided key
*
* @param keyStroke character representing the key to release
*/
UINT keyUp(char keyStroke) const;
/**
* @brief Clicks (types) the provided key with the duration between each press and release
*
* @param keyStroke character representing the key to type
* @param clickDuration milliseconds between each action
*/
UINT keyClick(char keyStroke, DWORD clickDuration = 0) const;
/**
* @brief Clicks (types) the provided keys with the duration between each press and release (no additional duration between subsequent characters)
*
* @param keyStrokes characters representing the keys to type
* @param durationBetweenKeyStrokes milliseconds between each action
*/
UINT keyClick(const char keyStrokes[], DWORD clickDurationForEachKey = 0) const;
/**
* @brief Presses Left Control, then the provided keyStroke, waits clickDuration milliseconds, then releases the provided keyStroke, and finally releases Left Control
*
* @param keyStroke character representing the key to type
* @param clickDuration milliseconds between each action
*/
UINT ctrlPlusKeyClick(char keyStroke, DWORD clickDuration = 0) const;
/**
* @brief Presses Left Control, performs keyClick(keyStrokes, clickDurationForEachKey), and finally releases Left Control
*
* @param keyStrokes character representing the key to type
* @param clickDurationForEachKey milliseconds between each action
*/
UINT ctrlPlusKeyClick(const char keyStrokes[], DWORD clickDurationForEachKey = 0) const;
/**
* @brief Presses Shift, then the provided keyStroke, waits clickDuration milliseconds, then releases the provided keyStroke, and finally releases Shift
*
* @param keyStrokes character representing the key to type
* @param clickDurationForEachKey milliseconds between each action
*/
UINT shiftPlusKeyClick(char keyStroke, DWORD clickDuration = 0) const;
/**
* @brief Presses Shift, performs keyClick(keyStrokes, clickDurationForEachKey), and finally releases Shift
*
* @param keyStrokes character representing the key to type
* @param clickDurationForEachKey milliseconds between each action
*/
UINT shiftPlusKeyClick(const char keyStrokes[], DWORD clickDurationForEachKey = 0) const;
/**
* @brief Clicks f1, f2, f3, f4, f5 based on params
*
* @param fKey f#
* @param clickDuration
*/
UINT fKeyClick(int fKey, DWORD clickDuration = 0) const;
/**
* @brief Presses down f1 - f12 based on params
*
* @param fKey f#
* @param clickDuration
*/
UINT fKeyDown(int fKey) const;
/**
* @brief Releases f1 - f12 based on params
*
* @param fKey f#
* @param clickDuration
*/
UINT fKeyUp(int fKey) const;
/**
* @brief Clicks the Enter Key
*
* @param clickDuration milliseconds
*/
UINT enterKeyClick(DWORD clickDuration = 0) const;
/**
* @brief Clicks the Escape Key
*
* @param clickDuration milliseconds
*/
UINT escapeKeyClick(DWORD clickDuration = 0) const;
UINT backspaceKeyClick(DWORD clickDuration = 0) const;
// Reader
int updateScreenBuffer();
BYTE getRed(const POINT& p) const;
BYTE getGreen(const POINT& p) const;
BYTE getBlue(const POINT& p) const;
/**
* @brief Compares the Euclidean Color Distance between the provided Pixel and the Screen Buffer
*
* @param pix Pixel to compare to the screen buffer
* @param tolerance Value at which (or below) the difference is negligible
* @return BOOL true - close enough; false - different
*/
BOOL isPixelSimilar(const Pixel& pix, unsigned short tolerance = 0.1) const;
/**
* @brief Determines if the provided Pixel matches the Screen Buffer
*
* @param pix Pixel to compare to the screen buffer
* @return BOOL true - equivalent; false - not equivalent
*/
BOOL isPixelEqual(const Pixel& pix) const;
int height() const;
int width() const;
};