-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyInput.cpp
More file actions
211 lines (193 loc) · 4.47 KB
/
Copy pathKeyInput.cpp
File metadata and controls
211 lines (193 loc) · 4.47 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
/*************************************************
**Name : Emory Wynn **
**Student# : 100655604 **
**note : please run this aplication in debug **
**************************************************/
#include "KeyInput.h"
std::unordered_map<int, bool> KeyInput::enter;
void KeyInput::setTyped(std::string str)
{
typing = str;
}
void KeyInput::setTypedLength(int l)
{
length = l;
}
void KeyInput::clearType()
{
typing = "";
}
int KeyInput::getTypedSize()
{
return typing.size();
}
const char* KeyInput::type()
{
//OutputDebugStringA((std::to_string(count) + "\n").c_str());
if(!press(pressed) && pressed != 0)
count2 = wait2;
if((length > -1 ? typing.size() < (unsigned)length : false))
{
if(count2++ >= wait2)
{
count2 = 0;
//numpad nums & regular nums
for(short a = 0x30; a - 0x30 < 10; a++)
{
if(press(pressed = a) || (press(pressed = a + 48) && GetKeyState(VK_NUMLOCK)))
if(!press(VK_SHIFT))
{
wait2 = amount;
return (typing += (char)a).c_str();
} else
{
wait2 = amount;
return (typing += numShiftKeys[a - 0x30]).c_str();
}
}
//numpad operators
for(short a = 0x6A; a - 0x6A < 2; a++)
{
if(press(pressed = a))
if(GetKeyState(VK_NUMLOCK))
{
wait2 = amount;
return (typing += operators[a - 0x6A]).c_str();
}
}
for(short a = 0x6D; a - 0x6D < 3; a++)
{
if(press(pressed = a))
if(GetKeyState(VK_NUMLOCK))
{
wait2 = amount;
return (typing += operators[a - 0x6D + 2]).c_str();
}
}
//letters
for(short a = 0x41; a - 0x41 < 26; a++)
{
if(press(pressed = a))
if(press(VK_SHIFT) || GetKeyState(VK_CAPITAL))
{
wait2 = amount;
return (typing += (char)a).c_str();
} else
{
wait2 = amount;
return (typing += a + 32).c_str();
}
}
//OEM (dual use buttons)
if(press(pressed = 0xBA))
{
if(press(VK_SHIFT))
{
wait2 = amount;
return (typing += symbalShiftKeys[0]).c_str();
} else
{
wait2 = amount;
return (typing += symbalKeys[0]).c_str();
}
}
for(short a = 0xBF; a - 0xBF < 2; a++)
{
if(press(pressed = a))
if(press(VK_SHIFT))
{
wait2 = amount;
return (typing += symbalShiftKeys[a - 0xBF + 1]).c_str();
} else
{
wait2 = amount;
return (typing += symbalKeys[a - 0xBF + 1]).c_str();
}
}
for(short a = 0xDB; a - 0xDB < 4; a++)
{
if(press(pressed = a))
if(press(VK_SHIFT))
{
wait2 = amount;
return (typing += symbalShiftKeys[a - 0xDB + 3]).c_str();
} else
{
wait2 = amount;
return (typing += symbalKeys[a - 0xDB + 3]).c_str();
}
}
for(short a = 0xBB; a - 0XBB < 4; a++)
{
if(press(pressed = a))
if(press(VK_SHIFT))
{
wait2 = amount;
return (typing += symbalShiftKeys[a - 0XBB + 7]).c_str();
} else
{
wait2 = amount;
return (typing += symbalKeys[a - 0XBB + 7]).c_str();
}
}
wait2 = 0;
pressed = 0;
}
} else
{
for(int x = 0; x < 256; x++)
(char) (GetAsyncKeyState(x) >> 8);
}
if(count++ == wait)
{
count = 0;
if(!typing.empty() && press(VK_BACK))
{
wait = (wait == 0 ? 200 : 25);
return (typing = typing.substr(0, typing.size() - 1)).c_str();
} else if(stroke(VK_SPACE))
return (typing += ' ').c_str();
wait = 0;
}
return typing.c_str();
}
/*
bool stroke(int key);
* key - The key which is pressed. You can either
use VK_KEYS (i.e. VK_RIGHT) or characters
(Note: characters must be in uppercase)
to be checked if key is pressed and then released
*/
bool KeyInput::stroke(int key)
{
if(GetAsyncKeyState(key))
enter[key] = true;
else if(enter[key] && !GetAsyncKeyState(key))
{
enter[key] = false;
return true;
}
return false;
}
/*
bool press(int key)
* key - The key which is pressed. You can either
use VK_KEYS (i.e. VK_RIGHT) or characters
(Note: characters must be in uppercase) to be
checked if key is pressed
*/
bool KeyInput::press(int key)
{
return GetAsyncKeyState(key);
}
/*
bool release(int key)
* key - The key which is pressed. You can either
use VK_KEYS (i.e. VK_RIGHT) or characters
(Note: characters must be in uppercase) to be
checked if key is released
*/
bool KeyInput::release(int key)
{
return !GetAsyncKeyState(key);
}