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