DEADSOFTWARE

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