bd23877f1b3fba0a2472cde74e7944fee7419a8f
1 /* Copyright (C) 2020 SovietPony
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 static char keystate
[KEY__LAST
+ 1];
22 const char *I_key_to_string (int key
) {
24 case KEY_0
: return "0";
25 case KEY_1
: return "1";
26 case KEY_2
: return "2";
27 case KEY_3
: return "3";
28 case KEY_4
: return "4";
29 case KEY_5
: return "5";
30 case KEY_6
: return "6";
31 case KEY_7
: return "7";
32 case KEY_8
: return "8";
33 case KEY_9
: return "9";
34 case KEY_A
: return "A";
35 case KEY_B
: return "B";
36 case KEY_C
: return "C";
37 case KEY_D
: return "D";
38 case KEY_E
: return "E";
39 case KEY_F
: return "F";
40 case KEY_G
: return "G";
41 case KEY_H
: return "H";
42 case KEY_I
: return "I";
43 case KEY_J
: return "J";
44 case KEY_K
: return "K";
45 case KEY_L
: return "L";
46 case KEY_M
: return "M";
47 case KEY_N
: return "N";
48 case KEY_O
: return "O";
49 case KEY_P
: return "P";
50 case KEY_Q
: return "Q";
51 case KEY_R
: return "R";
52 case KEY_S
: return "S";
53 case KEY_T
: return "T";
54 case KEY_U
: return "U";
55 case KEY_V
: return "V";
56 case KEY_W
: return "W";
57 case KEY_X
: return "X";
58 case KEY_Y
: return "Y";
59 case KEY_Z
: return "Z";
60 case KEY_RETURN
: return "RETURN";
61 case KEY_ESCAPE
: return "ESCAPE";
62 case KEY_BACKSPACE
: return "BACKSPACE";
63 case KEY_TAB
: return "TAB";
64 case KEY_SPACE
: return "SPACE";
65 case KEY_MINUS
: return "MINUS";
66 case KEY_EQUALS
: return "EQUALS";
67 case KEY_LEFTBRACKET
: return "LEFTBRACKET";
68 case KEY_RIGHTBRACKET
: return "RIGHTBRACKET";
69 case KEY_BACKSLASH
: return "BACKSLASH";
70 case KEY_SEMICOLON
: return "SEMICOLON";
71 case KEY_APOSTROPHE
: return "APOSTROPHE";
72 case KEY_GRAVE
: return "GRAVE";
73 case KEY_COMMA
: return "COMMA";
74 case KEY_PERIOD
: return "PERIOD";
75 case KEY_SLASH
: return "SLASH";
76 case KEY_CAPSLOCK
: return "CAPSLOCK";
77 case KEY_F1
: return "F1";
78 case KEY_F2
: return "F2";
79 case KEY_F3
: return "F3";
80 case KEY_F4
: return "F4";
81 case KEY_F5
: return "F5";
82 case KEY_F6
: return "F6";
83 case KEY_F7
: return "F7";
84 case KEY_F8
: return "F8";
85 case KEY_F9
: return "F9";
86 case KEY_F10
: return "F10";
87 case KEY_F11
: return "F11";
88 case KEY_F12
: return "F12";
89 case KEY_PRINTSCREEN
: return "PRINTSCREEN";
90 case KEY_SCROLLLOCK
: return "SCROLLLOCK";
91 case KEY_PAUSE
: return "PAUSE";
92 case KEY_INSERT
: return "INSERT";
93 case KEY_HOME
: return "HOME";
94 case KEY_PAGEUP
: return "PAGEUP";
95 case KEY_DELETE
: return "DELETE";
96 case KEY_END
: return "END";
97 case KEY_PAGEDOWN
: return "PAGEDOWN";
98 case KEY_RIGHT
: return "RIGHT";
99 case KEY_LEFT
: return "LEFT";
100 case KEY_DOWN
: return "DOWN";
101 case KEY_UP
: return "UP";
102 case KEY_NUMLOCK
: return "NUMLOCK";
103 case KEY_KP_DIVIDE
: return "KP_DIVIDE";
104 case KEY_KP_MULTIPLY
: return "KP_MULTIPLY";
105 case KEY_KP_MINUS
: return "KP_MINUS";
106 case KEY_KP_PLUS
: return "KP_PLUS";
107 case KEY_KP_ENTER
: return "KP_ENTER";
108 case KEY_KP_0
: return "KP_0";
109 case KEY_KP_1
: return "KP_1";
110 case KEY_KP_2
: return "KP_2";
111 case KEY_KP_3
: return "KP_3";
112 case KEY_KP_4
: return "KP_4";
113 case KEY_KP_5
: return "KP_5";
114 case KEY_KP_6
: return "KP_6";
115 case KEY_KP_7
: return "KP_7";
116 case KEY_KP_8
: return "KP_8";
117 case KEY_KP_9
: return "KP_9";
118 case KEY_KP_PERIOD
: return "KP_PERIOD";
119 case KEY_SYSREQ
: return "SYSREQ";
120 case KEY_LCTRL
: return "LCTRL";
121 case KEY_LSHIFT
: return "LSHIFT";
122 case KEY_LALT
: return "LALT";
123 case KEY_LSUPER
: return "LSUPER";
124 case KEY_RCTRL
: return "RCTRL";
125 case KEY_RSHIFT
: return "RSHIFT";
126 case KEY_RALT
: return "RALT";
127 case KEY_RSUPER
: return "RSUPER";
128 default: return "UNKNOWN";
132 int I_string_to_key (const char *str
) {
133 if (strcasecmp(str
, "0") == 0) return KEY_0
;
134 else if (strcasecmp(str
, "1") == 0) return KEY_1
;
135 else if (strcasecmp(str
, "2") == 0) return KEY_2
;
136 else if (strcasecmp(str
, "3") == 0) return KEY_3
;
137 else if (strcasecmp(str
, "4") == 0) return KEY_4
;
138 else if (strcasecmp(str
, "5") == 0) return KEY_5
;
139 else if (strcasecmp(str
, "6") == 0) return KEY_6
;
140 else if (strcasecmp(str
, "7") == 0) return KEY_7
;
141 else if (strcasecmp(str
, "8") == 0) return KEY_8
;
142 else if (strcasecmp(str
, "9") == 0) return KEY_9
;
143 else if (strcasecmp(str
, "A") == 0) return KEY_A
;
144 else if (strcasecmp(str
, "B") == 0) return KEY_B
;
145 else if (strcasecmp(str
, "C") == 0) return KEY_C
;
146 else if (strcasecmp(str
, "D") == 0) return KEY_D
;
147 else if (strcasecmp(str
, "E") == 0) return KEY_E
;
148 else if (strcasecmp(str
, "F") == 0) return KEY_F
;
149 else if (strcasecmp(str
, "G") == 0) return KEY_G
;
150 else if (strcasecmp(str
, "H") == 0) return KEY_H
;
151 else if (strcasecmp(str
, "I") == 0) return KEY_I
;
152 else if (strcasecmp(str
, "J") == 0) return KEY_J
;
153 else if (strcasecmp(str
, "K") == 0) return KEY_K
;
154 else if (strcasecmp(str
, "L") == 0) return KEY_L
;
155 else if (strcasecmp(str
, "M") == 0) return KEY_M
;
156 else if (strcasecmp(str
, "N") == 0) return KEY_N
;
157 else if (strcasecmp(str
, "O") == 0) return KEY_O
;
158 else if (strcasecmp(str
, "P") == 0) return KEY_P
;
159 else if (strcasecmp(str
, "Q") == 0) return KEY_Q
;
160 else if (strcasecmp(str
, "R") == 0) return KEY_R
;
161 else if (strcasecmp(str
, "S") == 0) return KEY_S
;
162 else if (strcasecmp(str
, "T") == 0) return KEY_T
;
163 else if (strcasecmp(str
, "U") == 0) return KEY_U
;
164 else if (strcasecmp(str
, "V") == 0) return KEY_V
;
165 else if (strcasecmp(str
, "W") == 0) return KEY_W
;
166 else if (strcasecmp(str
, "X") == 0) return KEY_X
;
167 else if (strcasecmp(str
, "Y") == 0) return KEY_Y
;
168 else if (strcasecmp(str
, "Z") == 0) return KEY_Z
;
169 else if (strcasecmp(str
, "RETURN") == 0) return KEY_RETURN
;
170 else if (strcasecmp(str
, "ESCAPE") == 0) return KEY_ESCAPE
;
171 else if (strcasecmp(str
, "BACKSPACE") == 0) return KEY_BACKSPACE
;
172 else if (strcasecmp(str
, "TAB") == 0) return KEY_TAB
;
173 else if (strcasecmp(str
, "SPACE") == 0) return KEY_SPACE
;
174 else if (strcasecmp(str
, "MINUS") == 0) return KEY_MINUS
;
175 else if (strcasecmp(str
, "EQUALS") == 0) return KEY_EQUALS
;
176 else if (strcasecmp(str
, "LEFTBRACKET") == 0) return KEY_LEFTBRACKET
;
177 else if (strcasecmp(str
, "RIGHTBRACKET") == 0) return KEY_RIGHTBRACKET
;
178 else if (strcasecmp(str
, "BACKSLASH") == 0) return KEY_BACKSLASH
;
179 else if (strcasecmp(str
, "SEMICOLON") == 0) return KEY_SEMICOLON
;
180 else if (strcasecmp(str
, "APOSTROPHE") == 0) return KEY_APOSTROPHE
;
181 else if (strcasecmp(str
, "GRAVE") == 0) return KEY_GRAVE
;
182 else if (strcasecmp(str
, "COMMA") == 0) return KEY_COMMA
;
183 else if (strcasecmp(str
, "PERIOD") == 0) return KEY_PERIOD
;
184 else if (strcasecmp(str
, "SLASH") == 0) return KEY_SLASH
;
185 else if (strcasecmp(str
, "CAPSLOCK") == 0) return KEY_CAPSLOCK
;
186 else if (strcasecmp(str
, "F1") == 0) return KEY_F1
;
187 else if (strcasecmp(str
, "F2") == 0) return KEY_F2
;
188 else if (strcasecmp(str
, "F3") == 0) return KEY_F3
;
189 else if (strcasecmp(str
, "F4") == 0) return KEY_F4
;
190 else if (strcasecmp(str
, "F5") == 0) return KEY_F5
;
191 else if (strcasecmp(str
, "F6") == 0) return KEY_F6
;
192 else if (strcasecmp(str
, "F7") == 0) return KEY_F7
;
193 else if (strcasecmp(str
, "F8") == 0) return KEY_F8
;
194 else if (strcasecmp(str
, "F9") == 0) return KEY_F9
;
195 else if (strcasecmp(str
, "F10") == 0) return KEY_F10
;
196 else if (strcasecmp(str
, "F11") == 0) return KEY_F11
;
197 else if (strcasecmp(str
, "F12") == 0) return KEY_F12
;
198 else if (strcasecmp(str
, "PRINTSCREEN") == 0) return KEY_PRINTSCREEN
;
199 else if (strcasecmp(str
, "SCROLLLOCK") == 0) return KEY_SCROLLLOCK
;
200 else if (strcasecmp(str
, "PAUSE") == 0) return KEY_PAUSE
;
201 else if (strcasecmp(str
, "INSERT") == 0) return KEY_INSERT
;
202 else if (strcasecmp(str
, "HOME") == 0) return KEY_HOME
;
203 else if (strcasecmp(str
, "PAGEUP") == 0) return KEY_PAGEUP
;
204 else if (strcasecmp(str
, "DELETE") == 0) return KEY_DELETE
;
205 else if (strcasecmp(str
, "END") == 0) return KEY_END
;
206 else if (strcasecmp(str
, "PAGEDOWN") == 0) return KEY_PAGEDOWN
;
207 else if (strcasecmp(str
, "RIGHT") == 0) return KEY_RIGHT
;
208 else if (strcasecmp(str
, "LEFT") == 0) return KEY_LEFT
;
209 else if (strcasecmp(str
, "DOWN") == 0) return KEY_DOWN
;
210 else if (strcasecmp(str
, "UP") == 0) return KEY_UP
;
211 else if (strcasecmp(str
, "NUMLOCK") == 0) return KEY_NUMLOCK
;
212 else if (strcasecmp(str
, "KP_DIVIDE") == 0) return KEY_KP_DIVIDE
;
213 else if (strcasecmp(str
, "KP_MULTIPLY") == 0) return KEY_KP_MULTIPLY
;
214 else if (strcasecmp(str
, "KP_MINUS") == 0) return KEY_KP_MINUS
;
215 else if (strcasecmp(str
, "KP_PLUS") == 0) return KEY_KP_PLUS
;
216 else if (strcasecmp(str
, "KP_ENTER") == 0) return KEY_KP_ENTER
;
217 else if (strcasecmp(str
, "KP_0") == 0) return KEY_KP_0
;
218 else if (strcasecmp(str
, "KP_1") == 0) return KEY_KP_1
;
219 else if (strcasecmp(str
, "KP_2") == 0) return KEY_KP_2
;
220 else if (strcasecmp(str
, "KP_3") == 0) return KEY_KP_3
;
221 else if (strcasecmp(str
, "KP_4") == 0) return KEY_KP_4
;
222 else if (strcasecmp(str
, "KP_5") == 0) return KEY_KP_5
;
223 else if (strcasecmp(str
, "KP_6") == 0) return KEY_KP_6
;
224 else if (strcasecmp(str
, "KP_7") == 0) return KEY_KP_7
;
225 else if (strcasecmp(str
, "KP_8") == 0) return KEY_KP_8
;
226 else if (strcasecmp(str
, "KP_9") == 0) return KEY_KP_9
;
227 else if (strcasecmp(str
, "KP_PERIOD") == 0) return KEY_KP_PERIOD
;
228 else if (strcasecmp(str
, "SYSREQ") == 0) return KEY_SYSREQ
;
229 else if (strcasecmp(str
, "LCTRL") == 0) return KEY_LCTRL
;
230 else if (strcasecmp(str
, "LSHIFT") == 0) return KEY_LSHIFT
;
231 else if (strcasecmp(str
, "LALT") == 0) return KEY_LALT
;
232 else if (strcasecmp(str
, "LSUPER") == 0) return KEY_LSUPER
;
233 else if (strcasecmp(str
, "RCTRL") == 0) return KEY_RCTRL
;
234 else if (strcasecmp(str
, "RSHIFT") == 0) return KEY_RSHIFT
;
235 else if (strcasecmp(str
, "RALT") == 0) return KEY_RALT
;
236 else if (strcasecmp(str
, "RSUPER") == 0) return KEY_RSUPER
;
237 else return KEY_UNKNOWN
;
240 int I_pressed (int key
) {
241 assert(key
>= 0 && key
<= KEY__LAST
);
242 return keystate
[key
];
245 void I_press (int key
, int down
) {
246 assert(key
>= 0 && key
<= KEY__LAST
);
247 keystate
[key
] = down
!= 0;