-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
274 lines (230 loc) · 7.01 KB
/
input.h
File metadata and controls
274 lines (230 loc) · 7.01 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
#ifndef INPUT_H_INCLUDED
#define INPUT_H_INCLUDED
#include "variables.h"
class Mouse
{
public:
void update()//update the state of the mouse
{
if(GetKeyState(VK_LBUTTON) < 0)
{
if(held)
clicked = false;
else
clicked = held = true;
}
else
clicked = held = false;
GetCursorPos(&position);
GetWindowRect(hwnd, &r);
position.y = position.y - r.top - 30;//30 is the size of the title bar
position.x = position.x - r.left - 8;//idk what 8 is it's also for correction
#ifdef VARIABLES_H_INCLUDED
//find out over which cell the mouse hovers
mi = (this->pos().y)/cell_size_px_y;
mj = (this->pos().x)/cell_size_px_x;
#endif // VARIABLES_H_INCLUDED
}
POINT pos() const noexcept {
return this->position;
}
bool isHeld() const noexcept {
return this->held;
}
bool isClicked() const noexcept {
return this->clicked;
}
Mouse() {
clicked = false;
held = false;
position.x = position.y =0;
}
private:
RECT r;
bool held;
bool clicked;
POINT position;
}mouse;
class Keyboard
{
public:
void update() noexcept {
_any_pressed = _any_held = false;
key = 0;
for (int i = 5; i <= 250; ++i)
{
if(GetKeyState(i) < 0)
{
if(keys[(unsigned)i] == 0)
{
keys[(unsigned)i] = 1;
key = (wchar_t)i;
_any_pressed = true;
}
else if (keys[(unsigned)i] == 1)
{
keys[(unsigned)i] = 2;
}
else _any_held = true;
}
else keys[(unsigned)i] = 0;
}
for (int i = 186; i <= 192; ++i)
if (keys[i] > 0){
keys[L";=,-./`"[i-186]] = keys[i];
key = L";=,-./`"[i-186];
}
for (int i = 0; i < 4; ++i)
if (keys[_miscellaneous[i]] > 0){
keys[L"[]'\\"[i]] = keys[_miscellaneous[i]];
key = L"[]'\\"[i];
}
if (keys[VK_SHIFT] > 0)
{
for (int i = '0'; i <= '9'; ++i)
if (keys[i] > 0)
{
keys[L")!@#$%^&*("[i-'0']] = keys[i];
key = L")!@#$%^&*("[i-'0'];
}
for (int i = 0; i < 10; ++i)
{
if (keys[L";=,-./`[]'\\"[i]] > 0)
{
keys[L":+<_>?~{}\"|"[i]] = keys[L";=,-./`[]'\\"[i]];
key = L":+<_>?~{}\"|"[i];
}
}
if (keys[L'\\'] > 0) {keys[L'|'] = keys[L'\\'];key = L'|';}
}
else
{
bool _big_alpha = false;
for (int i = 'A'; i <= 'Z'; ++i)
if (keys[i] > 0)
{
keys[i + 'a' - 'A'] = keys[i];
key = i + 'a' - 'A';
_big_alpha = true;
}
if (!_big_alpha)
{
int i = 0;
for (wchar_t c : L"okjm")
{
if (keys[(int)c] > 0)
{
keys[L"/+*-"[i]] = keys[(int)c];
key = L"/+*-"[i];
}
++i;
}
}
}//VK_SHIFT not pressed
if (keys[220] > 0)
{
if (keys[VK_SHIFT] > 0) {
keys['|'] = keys[220];
key = '|';
} else {
keys['\\'] = keys[220];
key = '\\';
}
}
}//void update
bool isKeyPressed() const noexcept {
return _any_pressed;
}
bool isKeyHeld() const noexcept {
return _any_held;
}
bool isKeyPressed(int __key) const noexcept {
if (__key == 39 && keys[222] == 1) return false;
return keys[__key] == 1 && keys[VK_SHIFT] == 0;
}
bool isKeyHeld(int __key) const noexcept {
if (__key == 39 && keys[222] == 2) return false;
return keys[__key] == 2 && keys[VK_SHIFT] == 0;
}
bool isKeyPressed(char __key) const noexcept {
if (__key == '\'') return keys[222] == 1;
else if (__key < '0' || __key > 'z'){
if (keys[VK_SHIFT] > 0 && keys[(int)__key] == 1)
return true;
}
else if (keys[(int)__key] == 1) return true;
return false;
}
bool isKeyHeld(char __key) const noexcept {
if (__key == '\'') return keys[222] == 2;
else if (__key < '0' || __key > 'z'){
if (keys[VK_SHIFT] > 0 && keys[(int)__key] == 2)
return true;
}
else if (keys[(int)__key] == 1) return true;
return false;
}
bool isAlphaPressed() const noexcept {
if (isKeyHeld(VK_CONTROL)) return false;
for (int i = 'A'; i <= 'Z'; ++i)
if (keys[i] == 1)
return true;
return false;
}
bool isAlphaHeld() const noexcept {
if (isKeyHeld(VK_CONTROL)) return false;
for (int i = 'A'; i <= 'Z'; ++i)
if (keys[i] == 2)
return true;
return false;
}
bool isAlphaNumericPressed() const noexcept {
if (isKeyHeld(VK_CONTROL)) return false;
for (int i = '0'; i <= 'Z'; ++i)
if (keys[i] == 1)
return true;
return false;
}
bool isAlphaNumericHeld() const noexcept {
if (isKeyHeld(VK_CONTROL)) return false;
for (int i = '0'; i <= 'Z'; ++i)
if (keys[i] == 2)
return true;
return false;
}
bool isCharPressed() const noexcept {
if (isKeyHeld(VK_CONTROL)) return false;
if (keys[222] == 1) return true;
for (wchar_t c : L"-=[];\\,./_+\"|?`~* ")
if ((int)c >= 37 && (int)c <=40)
{if(keys[VK_SHIFT] > 0 && keys[(int)c] == 1)return true;}
else if (keys[(int)c] == 1)
return true;
for (size_t i = (size_t)'0'; i <= (size_t)'Z'; ++i)
if (keys[i] == 1)
return true;
return false;
}
bool isCharHeld() const noexcept {
if (isKeyHeld(VK_CONTROL)) return false;
if (keys[222] == 2) return true;
for (wchar_t c : L"-=[];\\,./_+\"|?`~* ")
if ((int)c >= 37 && (int)c <=40)
{if(keys[VK_SHIFT] > 0 && keys[(int)c] == 2)return true;}
else if (keys[(int)c] == 2)
return true;
for (size_t i = (size_t)'0'; i <= (size_t)'Z'; ++i)
if (keys[i] == 2)
return true;
return false;
}
wchar_t keyPressed() const noexcept {
return this->key;
}
protected:
wchar_t key;
int keys[256]{0};
bool _any_pressed, _any_held;
const int _miscellaneous[4] = {219, 221, 222, 226};
}keyboard;
#endif // INPUT_H_INCLUDED