-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.cc
141 lines (135 loc) · 2.6 KB
/
keyboard.cc
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
#include "keyboard.h"
#include "SDL2/SDL.h"
#include <iostream>
void Keyboard::resetKeys() {
for(int i=0;i<16;i++) {
keys[i] = false;
}
}
Keyboard::Keyboard() {
resetKeys();
}
bool Keyboard::isKeyPressed(int key) {
if(keys[key]) {
return true;
}
return false;
}
bool Keyboard::isExit() {
if(exit) return true;
return false;
}
void Keyboard::keyPressHandler() {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
exit = true;
break;
case(SDL_KEYDOWN):
switch(event.key.keysym.sym) {
case SDLK_1:
keys[1] = true;
break;
case SDLK_2:
keys[2] = true;
break;
case SDLK_3:
keys[3] = true;
break;
case SDLK_4:
keys[0xC] = true;
break;
case SDLK_q:
keys[4] = true;
break;
case SDLK_w:
keys[5] = true;
break;
case SDLK_e:
keys[6] = true;
break;
case SDLK_r:
keys[0xD] = true;
break;
case SDLK_a:
keys[7] = true;
break;
case SDLK_s:
keys[8] = true;
break;
case SDLK_d:
keys[9] = true;
break;
case SDLK_f:
keys[0xE] = true;
break;
case SDLK_z:
keys[0xA] = true;
break;
case SDLK_x:
keys[0] = true;
break;
case SDLK_c:
keys[0xB] = true;
break;
case SDLK_v:
keys[0xF] = true;
break;
}
break;
case(SDL_KEYUP):
switch(event.key.keysym.sym) {
case SDLK_1:
keys[1] = false;
break;
case SDLK_2:
keys[2] = false;
break;
case SDLK_3:
keys[3] = false;
break;
case SDLK_4:
keys[0xC] = false;
break;
case SDLK_q:
keys[4] = false;
break;
case SDLK_w:
keys[5] = false;
break;
case SDLK_e:
keys[6] = false;
break;
case SDLK_r:
keys[0xD] = false;
break;
case SDLK_a:
keys[7] = false;
break;
case SDLK_s:
keys[8] = false;
break;
case SDLK_d:
keys[9] = false;
break;
case SDLK_f:
keys[0xE] = false;
break;
case SDLK_z:
keys[0xA] = false;
break;
case SDLK_x:
keys[0] = false;
break;
case SDLK_c:
keys[0xB] = false;
break;
case SDLK_v:
keys[0xF] = false;
break;
}
break;
}
}
}