-
Notifications
You must be signed in to change notification settings - Fork 4
/
input.h
236 lines (198 loc) · 6.11 KB
/
input.h
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
#if !defined(INPUT_H)
#define INPUT_H
class Keyboard
{
public:
enum Key
{
KEY_0 = 48,
KEY_1 = 49,
KEY_2 = 50,
KEY_3 = 51,
KEY_4 = 52,
KEY_5 = 53,
KEY_6 = 54,
KEY_7 = 55,
KEY_8 = 56,
KEY_9 = 57,
KEY_A = 65,
KEY_B = 66,
KEY_C = 67,
KEY_D = 68,
KEY_E = 69,
KEY_F = 70,
KEY_G = 71,
KEY_H = 72,
KEY_I = 73,
KEY_J = 74,
KEY_K = 75,
KEY_L = 76,
KEY_M = 77,
KEY_N = 78,
KEY_O = 79,
KEY_P = 80,
KEY_Q = 81,
KEY_R = 82,
KEY_S = 83,
KEY_T = 84,
KEY_U = 85,
KEY_V = 86,
KEY_W = 87,
KEY_X = 88,
KEY_Y = 89,
KEY_Z = 90,
KEY_F1 = 112,
KEY_F2 = 113,
KEY_F3 = 114,
KEY_F4 = 115,
KEY_F5 = 116,
KEY_F6 = 117,
KEY_F7 = 118,
KEY_F8 = 119,
KEY_F9 = 120,
KEY_F10 = 121,
KEY_F11 = 122,
KEY_F12 = 123,
KEY_BACKSPACE = 8,
KEY_TAB = 9,
KEY_ENTER = 13,
KEY_CAPSLOCK = 20,
KEY_ESCAPE = 27,
KEY_SPACE = 32,
KEY_APP = 93,
KEY_SEMICOLON = 186,
KEY_ADD = 187,
KEY_COMMA = 188,
KEY_SUBTRACT = 189,
KEY_PERIOD = 190,
KEY_FWDSLASH = 191,
KEY_TILDE = 192,
KEY_LBRACKET = 219,
KEY_BACKSLASH = 220,
KEY_RBRACKET = 221,
KEY_APOSTROPHE = 222,
KEY_SHIFT = 16,
KEY_CTRL = 17,
KEY_LWIN = 91,
KEY_RWIN = 92,
KEY_LALT = 164,
KEY_RALT = 165,
KEY_INSERT = 45,
KEY_DELETE = 46,
KEY_HOME = 36,
KEY_END = 35,
KEY_PAGEUP = 33,
KEY_PAGEDOWN = 34,
KEY_UP = 38,
KEY_DOWN = 40,
KEY_RIGHT = 39,
KEY_LEFT = 37,
KEY_NUMLOCK = 144,
KEY_NUMPAD_DIVIDE = 111,
KEY_NUMPAD_MULTIPLY = 106,
KEY_NUMPAD_SUBTRACT = 109,
KEY_NUMPAD_ADD = 107,
KEY_NUMPAD_DECIMAL = 110,
KEY_NUMPAD_0 = 96,
KEY_NUMPAD_1 = 97,
KEY_NUMPAD_2 = 98,
KEY_NUMPAD_3 = 99,
KEY_NUMPAD_4 = 100,
KEY_NUMPAD_5 = 101,
KEY_NUMPAD_6 = 102,
KEY_NUMPAD_7 = 103,
KEY_NUMPAD_8 = 104,
KEY_NUMPAD_9 = 105,
};
static Keyboard &instance();
int getLastChar() const
{ return m_lastChar; }
bool keyDown(Key key) const
{ return (m_pCurrKeyStates[key] & 0x80) ? true : false; }
bool keyUp(Key key) const
{ return (m_pCurrKeyStates[key] & 0x80) ? false : true; }
bool keyPressed(Key key) const
{
return ((m_pCurrKeyStates[key] & 0x80)
&& !(m_pPrevKeyStates[key] & 0x80)) ? true : false;
}
void handleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void update();
private:
Keyboard();
~Keyboard();
int m_lastChar;
BYTE m_keyStates[2][256];
BYTE *m_pCurrKeyStates;
BYTE *m_pPrevKeyStates;
};
class Mouse
{
public:
enum MouseButton
{
BUTTON_LEFT = 0,
BUTTON_RIGHT = 1,
BUTTON_MIDDLE = 2
};
static Mouse &instance();
bool buttonDown(MouseButton button) const
{ return m_pCurrButtonStates[button]; }
bool buttonPressed(MouseButton button) const
{ return m_pCurrButtonStates[button] && !m_pPrevButtonStates[button]; }
bool buttonUp(MouseButton button) const
{ return !m_pCurrButtonStates[button]; }
bool cursorIsVisible() const
{ return m_cursorVisible; }
bool mouseSmoothingIsEnabled() const
{ return m_filterMouse; }
int xPosAbsolute() const
{ return m_xPosAbsolute; }
int yPosAbsolute() const
{ return m_yPosAbsolute; }
float xPosRelative() const
{ return m_xPosRelative; }
float yPosRelative() const
{ return m_yPosRelative; }
float wheelPos() const
{ return m_mouseWheel; }
bool attach(HWND hWnd);
void detach();
void handleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void hideCursor(bool hide);
void setPosition(UINT x, UINT y);
void smoothMouse(bool smooth);
void update();
private:
Mouse();
Mouse(const Mouse &);
Mouse &operator=(const Mouse &);
~Mouse();
void performMouseFiltering(float x, float y);
void performMouseSmoothing(float x, float y);
static const float WEIGHT_MODIFIER;
static const int HISTORY_BUFFER_SIZE = 10;
static const int TEMP_BUFFER_SIZE = 40;
static BYTE m_tempBuffer[TEMP_BUFFER_SIZE];
HWND m_hWnd;
int m_xPosAbsolute;
int m_yPosAbsolute;
int m_historyBufferSize;
int m_mouseIndex;
int m_wheelDelta;
int m_prevWheelDelta;
float m_mouseWheel;
float m_xPosRelative;
float m_yPosRelative;
float m_weightModifier;
float m_filtered[2];
float m_history[HISTORY_BUFFER_SIZE * 2];
float m_mouseMovementX[2];
float m_mouseMovementY[2];
bool m_filterMouse;
bool m_cursorVisible;
bool m_buttonStates[2][3];
bool *m_pCurrButtonStates;
bool *m_pPrevButtonStates;
};
#endif