DEADSOFTWARE

1bfd7f33407db727a8dd87c4848a392f09c64e74
[d2df-sdl.git] / src / engine / e_input.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit e_input;
18 interface
20 uses SysUtils, SDL2;
22 const
23 e_MaxKbdKeys = SDL_NUM_SCANCODES;
24 e_MaxJoys = 4;
25 e_MaxJoyBtns = 32;
26 e_MaxJoyAxes = 8;
27 e_MaxJoyHats = 8;
28 e_MaxVirtKeys = 48;
30 e_MaxJoyKeys = e_MaxJoyBtns + e_MaxJoyAxes*2 + e_MaxJoyHats*4;
32 e_MaxInputKeys = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1;
33 // $$$..$$$ - 321 Keyboard buttons/keys
34 // $$$..$$$ - 4*32 Joystick buttons
35 // $$$..$$$ - 8*2 Joystick axes (- and +)
36 // $$$..$$$ - 4*4 Joystick hats (L U R D)
37 // $$$..$$$ - 48 Virtual buttons/keys
39 KBRD_END = e_MaxKbdKeys;
40 JOYK_BEG = KBRD_END;
41 JOYK_END = JOYK_BEG + e_MaxJoyBtns*e_MaxJoys;
42 JOYA_BEG = JOYK_END;
43 JOYA_END = JOYA_BEG + e_MaxJoyAxes*2*e_MaxJoys;
44 JOYH_BEG = JOYA_END;
45 JOYH_END = JOYH_BEG + e_MaxJoyHats*4*e_MaxJoys;
46 VIRT_BEG = JOYH_END;
47 VIRT_END = VIRT_BEG + e_MaxVirtKeys;
49 // these are apparently used in g_gui and g_game and elsewhere
50 IK_INVALID = 0;
51 IK_ESCAPE = SDL_SCANCODE_ESCAPE;
52 IK_RETURN = SDL_SCANCODE_RETURN;
53 IK_KPRETURN= SDL_SCANCODE_KP_ENTER;
54 IK_ENTER = SDL_SCANCODE_RETURN;
55 IK_KPINSERT = SDL_SCANCODE_KP_0;
56 IK_UP = SDL_SCANCODE_UP;
57 IK_KPUP = SDL_SCANCODE_KP_8;
58 IK_DOWN = SDL_SCANCODE_DOWN;
59 IK_KPDOWN = SDL_SCANCODE_KP_2;
60 IK_LEFT = SDL_SCANCODE_LEFT;
61 IK_KPLEFT = SDL_SCANCODE_KP_4;
62 IK_RIGHT = SDL_SCANCODE_RIGHT;
63 IK_KPRIGHT = SDL_SCANCODE_KP_6;
64 IK_DELETE = SDL_SCANCODE_DELETE;
65 IK_HOME = SDL_SCANCODE_HOME;
66 IK_KPHOME = SDL_SCANCODE_KP_7;
67 IK_INSERT = SDL_SCANCODE_INSERT;
68 IK_SPACE = SDL_SCANCODE_SPACE;
69 IK_CONTROL = SDL_SCANCODE_LCTRL;
70 IK_SHIFT = SDL_SCANCODE_LSHIFT;
71 IK_ALT = SDL_SCANCODE_LALT;
72 IK_TAB = SDL_SCANCODE_TAB;
73 IK_PAGEUP = SDL_SCANCODE_PAGEUP;
74 IK_KPPAGEUP= SDL_SCANCODE_KP_9;
75 IK_PAGEDN = SDL_SCANCODE_PAGEDOWN;
76 IK_KPPAGEDN= SDL_SCANCODE_KP_3;
77 IK_KP5 = SDL_SCANCODE_KP_5;
78 IK_NUMLOCK = SDL_SCANCODE_NUMLOCKCLEAR;
79 IK_KPDIVIDE= SDL_SCANCODE_KP_DIVIDE;
80 IK_KPMULTIPLE= SDL_SCANCODE_KP_MULTIPLY;
81 IK_KPMINUS = SDL_SCANCODE_KP_MINUS;
82 IK_KPPLUS = SDL_SCANCODE_KP_PLUS;
83 IK_KPENTER = SDL_SCANCODE_KP_ENTER;
84 IK_KPDOT = SDL_SCANCODE_KP_PERIOD;
85 IK_CAPSLOCK= SDL_SCANCODE_CAPSLOCK;
86 IK_RSHIFT = SDL_SCANCODE_RSHIFT;
87 IK_CTRL = SDL_SCANCODE_LCTRL;
88 IK_RCTRL = SDL_SCANCODE_RCTRL;
89 IK_RALT = SDL_SCANCODE_RALT;
90 IK_WIN = SDL_SCANCODE_LGUI;
91 IK_RWIN = SDL_SCANCODE_RGUI;
92 IK_MENU = SDL_SCANCODE_MENU;
93 IK_PRINTSCR= SDL_SCANCODE_PRINTSCREEN;
94 IK_SCROLLLOCK= SDL_SCANCODE_SCROLLLOCK;
95 IK_LBRACKET= SDL_SCANCODE_LEFTBRACKET;
96 IK_RBRACKET= SDL_SCANCODE_RIGHTBRACKET;
97 IK_SEMICOLON= SDL_SCANCODE_SEMICOLON;
98 IK_QUOTE = SDL_SCANCODE_APOSTROPHE;
99 IK_BACKSLASH= SDL_SCANCODE_BACKSLASH;
100 IK_SLASH = SDL_SCANCODE_SLASH;
101 IK_COMMA = SDL_SCANCODE_COMMA;
102 IK_DOT = SDL_SCANCODE_PERIOD;
103 IK_EQUALS = SDL_SCANCODE_EQUALS;
104 IK_0 = SDL_SCANCODE_0;
105 IK_1 = SDL_SCANCODE_1;
106 IK_2 = SDL_SCANCODE_2;
107 IK_3 = SDL_SCANCODE_3;
108 IK_4 = SDL_SCANCODE_4;
109 IK_5 = SDL_SCANCODE_5;
110 IK_6 = SDL_SCANCODE_6;
111 IK_7 = SDL_SCANCODE_7;
112 IK_8 = SDL_SCANCODE_8;
113 IK_9 = SDL_SCANCODE_9;
114 IK_F1 = SDL_SCANCODE_F1;
115 IK_F2 = SDL_SCANCODE_F2;
116 IK_F3 = SDL_SCANCODE_F3;
117 IK_F4 = SDL_SCANCODE_F4;
118 IK_F5 = SDL_SCANCODE_F5;
119 IK_F6 = SDL_SCANCODE_F6;
120 IK_F7 = SDL_SCANCODE_F7;
121 IK_F8 = SDL_SCANCODE_F8;
122 IK_F9 = SDL_SCANCODE_F9;
123 IK_F10 = SDL_SCANCODE_F10;
124 IK_F11 = SDL_SCANCODE_F11;
125 IK_F12 = SDL_SCANCODE_F12;
126 IK_END = SDL_SCANCODE_END;
127 IK_KPEND = SDL_SCANCODE_KP_1;
128 IK_BACKSPACE = SDL_SCANCODE_BACKSPACE;
129 IK_BACKQUOTE = SDL_SCANCODE_GRAVE;
130 IK_GRAVE = SDL_SCANCODE_GRAVE;
131 IK_PAUSE = SDL_SCANCODE_PAUSE;
132 IK_Y = SDL_SCANCODE_Y;
133 IK_N = SDL_SCANCODE_N;
134 IK_W = SDL_SCANCODE_W;
135 IK_A = SDL_SCANCODE_A;
136 IK_S = SDL_SCANCODE_S;
137 IK_D = SDL_SCANCODE_D;
138 IK_Q = SDL_SCANCODE_Q;
139 IK_E = SDL_SCANCODE_E;
140 IK_H = SDL_SCANCODE_H;
141 IK_J = SDL_SCANCODE_J;
142 IK_T = SDL_SCANCODE_T;
143 IK_Z = SDL_SCANCODE_Z;
144 IK_MINUS = SDL_SCANCODE_MINUS;
145 // TODO: think of something better than this shit
146 IK_LASTKEY = SDL_NUM_SCANCODES-1;
148 VK_FIRSTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys;
149 VK_LEFT = VK_FIRSTKEY + 0;
150 VK_RIGHT = VK_FIRSTKEY + 1;
151 VK_UP = VK_FIRSTKEY + 2;
152 VK_DOWN = VK_FIRSTKEY + 3;
153 VK_FIRE = VK_FIRSTKEY + 4;
154 VK_OPEN = VK_FIRSTKEY + 5;
155 VK_JUMP = VK_FIRSTKEY + 6;
156 VK_CHAT = VK_FIRSTKEY + 7;
157 VK_ESCAPE = VK_FIRSTKEY + 8;
158 VK_0 = VK_FIRSTKEY + 9;
159 VK_1 = VK_FIRSTKEY + 10;
160 VK_2 = VK_FIRSTKEY + 11;
161 VK_3 = VK_FIRSTKEY + 12;
162 VK_4 = VK_FIRSTKEY + 13;
163 VK_5 = VK_FIRSTKEY + 14;
164 VK_6 = VK_FIRSTKEY + 15;
165 VK_7 = VK_FIRSTKEY + 16;
166 VK_8 = VK_FIRSTKEY + 17;
167 VK_9 = VK_FIRSTKEY + 18;
168 VK_A = VK_FIRSTKEY + 19;
169 VK_B = VK_FIRSTKEY + 20;
170 VK_C = VK_FIRSTKEY + 21;
171 VK_D = VK_FIRSTKEY + 22;
172 VK_E = VK_FIRSTKEY + 23;
173 VK_F = VK_FIRSTKEY + 24;
174 VK_CONSOLE = VK_FIRSTKEY + 25;
175 VK_STATUS = VK_FIRSTKEY + 26;
176 VK_TEAM = VK_FIRSTKEY + 27;
177 VK_PREV = VK_FIRSTKEY + 28;
178 VK_NEXT = VK_FIRSTKEY + 29;
179 VK_STRAFE = VK_FIRSTKEY + 30;
180 VK_LSTRAFE = VK_FIRSTKEY + 31;
181 VK_RSTRAFE = VK_FIRSTKEY + 32;
182 VK_PRINTSCR = VK_FIRSTKEY + 33;
183 VK_SHOWKBD = VK_FIRSTKEY + 34;
184 VK_HIDEKBD = VK_FIRSTKEY + 35;
185 VK_LASTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1;
187 AX_MINUS = 0;
188 AX_PLUS = 1;
189 HAT_LEFT = 0;
190 HAT_UP = 1;
191 HAT_RIGHT = 2;
192 HAT_DOWN = 3;
194 JOY0_ATTACK = JOYK_BEG + 0*e_MaxJoyBtns + 0;
195 JOY1_ATTACK = JOYK_BEG + 1*e_MaxJoyBtns + 0;
196 JOY2_ATTACK = JOYK_BEG + 2*e_MaxJoyBtns + 0;
197 JOY3_ATTACK = JOYK_BEG + 3*e_MaxJoyBtns + 0;
198 JOY0_NEXT = JOYK_BEG + 0*e_MaxJoyBtns + 1;
199 JOY1_NEXT = JOYK_BEG + 1*e_MaxJoyBtns + 1;
200 JOY2_NEXT = JOYK_BEG + 2*e_MaxJoyBtns + 1;
201 JOY3_NEXT = JOYK_BEG + 3*e_MaxJoyBtns + 1;
202 JOY0_JUMP = JOYK_BEG + 0*e_MaxJoyBtns + 2;
203 JOY1_JUMP = JOYK_BEG + 1*e_MaxJoyBtns + 2;
204 JOY2_JUMP = JOYK_BEG + 2*e_MaxJoyBtns + 2;
205 JOY3_JUMP = JOYK_BEG + 3*e_MaxJoyBtns + 2;
206 JOY0_ACTIVATE = JOYK_BEG + 0*e_MaxJoyBtns + 3;
207 JOY1_ACTIVATE = JOYK_BEG + 1*e_MaxJoyBtns + 3;
208 JOY2_ACTIVATE = JOYK_BEG + 2*e_MaxJoyBtns + 3;
209 JOY3_ACTIVATE = JOYK_BEG + 3*e_MaxJoyBtns + 3;
210 JOY0_PREV = JOYK_BEG + 0*e_MaxJoyBtns + 4;
211 JOY1_PREV = JOYK_BEG + 1*e_MaxJoyBtns + 4;
212 JOY2_PREV = JOYK_BEG + 2*e_MaxJoyBtns + 4;
213 JOY3_PREV = JOYK_BEG + 3*e_MaxJoyBtns + 4;
215 JOY0_LEFT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
216 JOY1_LEFT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
217 JOY2_LEFT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
218 JOY3_LEFT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
219 JOY0_RIGHT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
220 JOY1_RIGHT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
221 JOY2_RIGHT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
222 JOY3_RIGHT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
223 JOY0_UP = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_UP;
224 JOY1_UP = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_UP;
225 JOY2_UP = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_UP;
226 JOY3_UP = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_UP;
227 JOY0_DOWN = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
228 JOY1_DOWN = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
229 JOY2_DOWN = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
230 JOY3_DOWN = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
232 function e_InitInput: Boolean;
233 procedure e_ReleaseInput;
234 procedure e_UnpressAllKeys;
235 procedure e_KeyUpDown (key: Integer; down: Boolean);
237 function e_KeyPressed (key: Integer): Boolean;
238 function e_AnyKeyPressed: Boolean;
239 function e_GetFirstKeyPressed: Integer;
240 function e_HasJoysticks: Boolean;
242 function e_JoyButtonToKey (id, btn: Integer): Integer;
243 function e_JoyAxisToKey (id, ax, dir: Integer): Integer;
244 function e_JoyHatToKey (id, hat, dir: Integer): Integer;
246 var
247 e_JoystickAvailable: array [0..e_MaxJoys - 1] of Boolean;
248 e_JoystickDeadzones: array [0..e_MaxJoys - 1] of Integer = (8192, 8192, 8192, 8192);
249 e_KeyNames: array [0..e_MaxInputKeys] of String;
251 implementation
253 var
254 InputBuffer: array [0..e_MaxInputKeys - 1] of Boolean;
256 procedure e_UnpressAllKeys;
257 var i: Integer;
258 begin
259 for i := 0 to High(InputBuffer) do
260 InputBuffer[i] := False
261 end;
263 procedure e_KeyUpDown (key: Integer; down: Boolean);
264 begin
265 ASSERT(key >= 0);
266 ASSERT(key < e_MaxInputKeys);
267 if key > 0 then
268 InputBuffer[key] := down
269 end;
271 procedure GenerateKeyNames;
272 var i, j, k: Integer;
273 begin
274 // keyboard key names
275 e_KeyNames[IK_0] := '0';
276 e_KeyNames[IK_1] := '1';
277 e_KeyNames[IK_2] := '2';
278 e_KeyNames[IK_3] := '3';
279 e_KeyNames[IK_4] := '4';
280 e_KeyNames[IK_5] := '5';
281 e_KeyNames[IK_6] := '6';
282 e_KeyNames[IK_7] := '7';
283 e_KeyNames[IK_8] := '8';
284 e_KeyNames[IK_9] := '9';
286 for i := IK_A to IK_Z do
287 e_KeyNames[i] := '' + chr(ord('a') + (i - IK_a));
289 e_KeyNames[IK_ESCAPE] := 'ESCAPE';
290 e_KeyNames[IK_ENTER] := 'ENTER';
291 e_KeyNames[IK_TAB] := 'TAB';
292 e_KeyNames[IK_BACKSPACE] := 'BACKSPACE';
293 e_KeyNames[IK_SPACE] := 'SPACE';
294 e_KeyNames[IK_UP] := 'UP';
295 e_KeyNames[IK_LEFT] := 'LEFT';
296 e_KeyNames[IK_RIGHT] := 'RIGHT';
297 e_KeyNames[IK_DOWN] := 'DOWN';
298 e_KeyNames[IK_INSERT] := 'INSERT';
299 e_KeyNames[IK_DELETE] := 'DELETE';
300 e_KeyNames[IK_HOME] := 'HOME';
301 e_KeyNames[IK_END] := 'END';
302 e_KeyNames[IK_PAGEUP] := 'PGUP';
303 e_KeyNames[IK_PAGEDN] := 'PGDOWN';
304 e_KeyNames[IK_KPINSERT] := 'PAD0';
305 e_KeyNames[IK_KPEND] := 'PAD1';
306 e_KeyNames[IK_KPDOWN] := 'PAD2';
307 e_KeyNames[IK_KPPAGEDN] := 'PAD3';
308 e_KeyNames[IK_KPLEFT] := 'PAD4';
309 e_KeyNames[IK_KP5] := 'PAD5';
310 e_KeyNames[IK_KPRIGHT] := 'PAD6';
311 e_KeyNames[IK_KPHOME] := 'PAD7';
312 e_KeyNames[IK_KPUP] := 'PAD8';
313 e_KeyNames[IK_KPPAGEUP] := 'PAD9';
314 e_KeyNames[IK_NUMLOCK] := 'NUM';
315 e_KeyNames[IK_KPDIVIDE] := 'PAD/';
316 e_KeyNames[IK_KPMULTIPLE] := 'PAD*';
317 e_KeyNames[IK_KPMINUS] := 'PAD-';
318 e_KeyNames[IK_KPPLUS] := 'PAD+';
319 e_KeyNames[IK_KPENTER] := 'PADENTER';
320 e_KeyNames[IK_KPDOT] := 'PAD.';
321 e_KeyNames[IK_CAPSLOCK] := 'CAPS';
322 e_KeyNames[IK_BACKQUOTE] := 'BACKQUOTE';
323 e_KeyNames[IK_F1] := 'F1';
324 e_KeyNames[IK_F2] := 'F2';
325 e_KeyNames[IK_F3] := 'F3';
326 e_KeyNames[IK_F4] := 'F4';
327 e_KeyNames[IK_F5] := 'F5';
328 e_KeyNames[IK_F6] := 'F6';
329 e_KeyNames[IK_F7] := 'F7';
330 e_KeyNames[IK_F8] := 'F8';
331 e_KeyNames[IK_F9] := 'F9';
332 e_KeyNames[IK_F10] := 'F10';
333 e_KeyNames[IK_F11] := 'F11';
334 e_KeyNames[IK_F12] := 'F12';
335 e_KeyNames[IK_SHIFT] := 'LSHIFT';
336 e_KeyNames[IK_RSHIFT] := 'RSHIFT';
337 e_KeyNames[IK_CTRL] := 'LCTRL';
338 e_KeyNames[IK_RCTRL] := 'RCTRL';
339 e_KeyNames[IK_ALT] := 'LALT';
340 e_KeyNames[IK_RALT] := 'RALT';
341 e_KeyNames[IK_WIN] := 'LWIN';
342 e_KeyNames[IK_RWIN] := 'RWIN';
343 e_KeyNames[IK_MENU] := 'MENU';
344 e_KeyNames[IK_PRINTSCR] := 'PSCRN';
345 e_KeyNames[IK_SCROLLLOCK] := 'SCROLL';
346 e_KeyNames[IK_PAUSE] := 'PAUSE';
347 e_KeyNames[IK_LBRACKET] := '[';
348 e_KeyNames[IK_RBRACKET] := ']';
349 e_KeyNames[IK_SEMICOLON] := ';';
350 e_KeyNames[IK_QUOTE] := '''';
351 e_KeyNames[IK_BACKSLASH] := '\';
352 e_KeyNames[IK_SLASH] := '/';
353 e_KeyNames[IK_COMMA] := ',';
354 e_KeyNames[IK_DOT] := '.';
355 e_KeyNames[IK_MINUS] := '-';
356 e_KeyNames[IK_EQUALS] := '=';
358 // joysticks
359 for j := 0 to e_MaxJoys-1 do
360 begin
361 k := JOYK_BEG + j * e_MaxJoyBtns;
362 // buttons
363 for i := 0 to e_MaxJoyBtns-1 do
364 e_KeyNames[k + i] := Format('JOY%dB%d', [j, i]);
365 k := JOYA_BEG + j * e_MaxJoyAxes * 2;
366 // axes
367 for i := 0 to e_MaxJoyAxes-1 do
368 begin
369 e_KeyNames[k + i*2 ] := Format('JOY%dA%d+', [j, i]);
370 e_KeyNames[k + i*2 + 1] := Format('JOY%dA%d-', [j, i]);
371 end;
372 k := JOYH_BEG + j * e_MaxJoyHats * 4;
373 // hats
374 for i := 0 to e_MaxJoyHats-1 do
375 begin
376 e_KeyNames[k + i*4 ] := Format('JOY%dD%dL', [j, i]);
377 e_KeyNames[k + i*4 + 1] := Format('JOY%dD%dU', [j, i]);
378 e_KeyNames[k + i*4 + 2] := Format('JOY%dD%dR', [j, i]);
379 e_KeyNames[k + i*4 + 3] := Format('JOY%dD%dD', [j, i]);
380 end;
381 end;
383 // vitrual keys
384 for i := 0 to e_MaxVirtKeys-1 do
385 e_KeyNames[VIRT_BEG + i] := 'VIRTUAL' + IntToStr(i);
386 end;
388 function e_HasJoysticks: Boolean;
389 var i: Integer;
390 begin
391 i := 0;
392 while (i < e_MaxJoys) and (e_JoystickAvailable[i] = False) do inc(i);
393 result := i < e_MaxJoys
394 end;
396 function e_InitInput: Boolean;
397 var i: Integer;
398 begin
399 for i := 0 to e_MaxJoys - 1 do
400 e_JoystickAvailable[i] := False;
401 GenerateKeyNames;
402 result := True
403 end;
405 procedure e_ReleaseInput;
406 var i: Integer;
407 begin
408 for i := 0 to e_MaxJoys - 1 do
409 e_JoystickAvailable[i] := False
410 end;
412 function e_KeyPressed (key: Integer): Boolean;
413 begin
414 ASSERT(key >= 0);
415 ASSERT(key < e_MaxInputKeys);
416 result := InputBuffer[key]
417 end;
419 function e_AnyKeyPressed: Boolean;
420 begin
421 result := e_GetFirstKeyPressed <> IK_INVALID;
422 end;
424 function e_GetFirstKeyPressed: Integer;
425 var i: Integer;
426 begin
427 i := 1;
428 while (i < e_MaxInputKeys) and (InputBuffer[i] = False) do inc(i);
429 if i < e_MaxInputKeys then
430 result := i
431 else
432 result := IK_INVALID
433 end;
435 function e_JoyButtonToKey (id, btn: Integer): Integer;
436 begin
437 ASSERT(id >= 0);
438 ASSERT(id < e_MaxJoys);
439 ASSERT(btn >= 0);
440 ASSERT(btn < e_MaxJoyBtns);
441 result := JOYK_BEG + id*e_MaxJoyBtns + btn
442 end;
444 function e_JoyAxisToKey (id, ax, dir: Integer): Integer;
445 begin
446 ASSERT(id >= 0);
447 ASSERT(id < e_MaxJoys);
448 ASSERT(ax >= 0);
449 ASSERT(ax < e_MaxJoyAxes);
450 ASSERT(dir in [AX_MINUS, AX_PLUS]);
451 result := JOYA_BEG + id*e_MaxJoyAxes*2 + ax*2 + dir
452 end;
454 function e_JoyHatToKey (id, hat, dir: Integer): Integer;
455 begin
456 ASSERT(id >= 0);
457 ASSERT(id < e_MaxJoys);
458 ASSERT(hat >= 0);
459 ASSERT(hat < e_MaxJoyHats);
460 ASSERT(dir in [HAT_LEFT, HAT_UP, HAT_RIGHT, HAT_DOWN]);
461 result := JOYH_BEG + id*e_MaxJoyHats*4 + hat*4 + dir
462 end;
464 end.