-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.h
92 lines (84 loc) · 1.58 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
#include "features.h"
typedef struct {
int value;
bool running;
} inputResult;
inputResult getInput(void) {
int value = 0;
bool running = true;
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = false;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.scancode) {
case SDL_SCANCODE_ESCAPE:
running = false;
break;
case SDL_SCANCODE_1:
value = 1;
break;
case SDL_SCANCODE_2:
value = 2;
break;
case SDL_SCANCODE_3:
value = 3;
break;
case SDL_SCANCODE_4:
value = 0xC;
break;
case SDL_SCANCODE_Q:
value = 4;
break;
case SDL_SCANCODE_W:
value = 5;
break;
case SDL_SCANCODE_E:
value = 6;
break;
case SDL_SCANCODE_R:
value = 0xD;
break;
case SDL_SCANCODE_A:
value = 7;
break;
case SDL_SCANCODE_S:
value = 8;
break;
case SDL_SCANCODE_D:
value = 9;
break;
case SDL_SCANCODE_F:
value = 0xE;
break;
case SDL_SCANCODE_Z:
value = 0xA;
break;
case SDL_SCANCODE_X:
value = 0;
break;
case SDL_SCANCODE_C:
value = 0xB;
break;
case SDL_SCANCODE_V:
value = 0xF;
break;
default:
fprintf(LOGFILE, "Unsupported key entered!\n");
break;
}
break;
default:
break;
}
}
inputResult out;
out.value = value + 1;
out.running = running;
if (value) {
fprintf(LOGFILE,"INPUT: value = %x, running = %d\n", value, running);
}
return out;
}