201 end; |
208 end; |
202 |
209 |
203 procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
210 procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
204 var code: LongInt; |
211 var code: LongInt; |
205 begin |
212 begin |
206 code:= event.keysym.sym; |
213 // TODO |
207 //MaskModifier(code, event.keysym.modifier); |
214 code:= LongInt(event.keysym.scancode); |
|
215 //writelntoconsole('[KEY] '+inttostr(code)+ ' -> ''' +KeyNames[code] + ''', type = '+inttostr(event.type_)); |
208 ProcessKey(code, event.type_ = SDL_KEYDOWN); |
216 ProcessKey(code, event.type_ = SDL_KEYDOWN); |
209 end; |
217 end; |
210 |
218 |
211 procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean); |
219 procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean); |
212 begin |
220 begin |
213 case event.button of |
221 //writelntoconsole('[MOUSE] '+inttostr(event.button)); |
214 SDL_BUTTON_LEFT: |
222 case event.button of |
215 ProcessKey(KeyNameToCode('mousel'), ButtonDown); |
223 SDL_BUTTON_LEFT: |
216 SDL_BUTTON_MIDDLE: |
224 ProcessKey(KeyNameToCode('mousel'), ButtonDown); |
217 ProcessKey(KeyNameToCode('mousem'), ButtonDown); |
225 SDL_BUTTON_MIDDLE: |
218 SDL_BUTTON_RIGHT: |
226 ProcessKey(KeyNameToCode('mousem'), ButtonDown); |
219 ProcessKey(KeyNameToCode('mouser'), ButtonDown); |
227 SDL_BUTTON_RIGHT: |
220 SDL_BUTTON_WHEELDOWN: |
228 ProcessKey(KeyNameToCode('mouser'), ButtonDown); |
221 ProcessKey(KeyNameToCode('wheeldown'), ButtonDown); |
229 SDL_BUTTON_WHEELDOWN: |
222 SDL_BUTTON_WHEELUP: |
230 ProcessKey(KeyNameToCode('wheeldown'), ButtonDown); |
223 ProcessKey(KeyNameToCode('wheelup'), ButtonDown); |
231 SDL_BUTTON_WHEELUP: |
224 end; |
232 ProcessKey(KeyNameToCode('wheelup'), ButtonDown); |
|
233 end; |
|
234 end; |
|
235 |
|
236 procedure ProcessMouseWheel(x, y: LongInt); |
|
237 begin |
|
238 //writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y)); |
|
239 if y > 0 then |
|
240 ProcessKey(KeyNameToCode('wheelup'), true) |
|
241 else if y < 0 then |
|
242 ProcessKey(KeyNameToCode('wheeldown'), true); |
225 end; |
243 end; |
226 |
244 |
227 procedure ResetKbd; |
245 procedure ResetKbd; |
228 var t: LongInt; |
246 var t: LongInt; |
229 begin |
247 begin |
230 for t:= 0 to cKbdMaxIndex do |
248 for t:= 0 to cKbdMaxIndex do |
231 if tkbd[t] then |
249 if tkbd[t] then |
232 ProcessKey(t, False); |
250 ProcessKey(t, False); |
233 end; |
251 end; |
234 |
252 |
|
253 |
|
254 procedure InitDefaultBinds; |
|
255 var i: Longword; |
|
256 begin |
|
257 DefaultBinds[KeyNameToCode('escape')]:= 'quit'; |
|
258 DefaultBinds[KeyNameToCode(_S'`')]:= 'history'; |
|
259 DefaultBinds[KeyNameToCode('delete')]:= 'rotmask'; |
|
260 |
|
261 //numpad |
|
262 //DefaultBinds[265]:= '+volup'; |
|
263 //DefaultBinds[256]:= '+voldown'; |
|
264 |
|
265 DefaultBinds[KeyNameToCode(_S'0')]:= '+volup'; |
|
266 DefaultBinds[KeyNameToCode(_S'9')]:= '+voldown'; |
|
267 DefaultBinds[KeyNameToCode(_S'8')]:= 'mute'; |
|
268 DefaultBinds[KeyNameToCode(_S'c')]:= 'capture'; |
|
269 DefaultBinds[KeyNameToCode(_S'r')]:= 'record'; |
|
270 DefaultBinds[KeyNameToCode(_S'h')]:= 'findhh'; |
|
271 DefaultBinds[KeyNameToCode(_S'p')]:= 'pause'; |
|
272 DefaultBinds[KeyNameToCode(_S's')]:= '+speedup'; |
|
273 DefaultBinds[KeyNameToCode(_S't')]:= 'chat'; |
|
274 DefaultBinds[KeyNameToCode(_S'y')]:= 'confirm'; |
|
275 |
|
276 DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
|
277 DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomin'; |
|
278 DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomout'; |
|
279 |
|
280 DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
|
281 |
|
282 |
|
283 DefaultBinds[KeyNameToCode('mousel')]:= '/put'; |
|
284 DefaultBinds[KeyNameToCode('mouser')]:= 'ammomenu'; |
|
285 DefaultBinds[KeyNameToCode('backspace')]:= 'hjump'; |
|
286 DefaultBinds[KeyNameToCode('tab')]:= 'switch'; |
|
287 DefaultBinds[KeyNameToCode('return')]:= 'ljump'; |
|
288 DefaultBinds[KeyNameToCode('space')]:= '+attack'; |
|
289 DefaultBinds[KeyNameToCode('up')]:= '+up'; |
|
290 DefaultBinds[KeyNameToCode('down')]:= '+down'; |
|
291 DefaultBinds[KeyNameToCode('left')]:= '+left'; |
|
292 DefaultBinds[KeyNameToCode('right')]:= '+right'; |
|
293 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise'; |
|
294 |
|
295 |
|
296 DefaultBinds[KeyNameToCode('j0a0u')]:= '+left'; |
|
297 DefaultBinds[KeyNameToCode('j0a0d')]:= '+right'; |
|
298 DefaultBinds[KeyNameToCode('j0a1u')]:= '+up'; |
|
299 DefaultBinds[KeyNameToCode('j0a1d')]:= '+down'; |
|
300 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i); |
|
301 for i:= 1 to 5 do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i); |
|
302 |
|
303 loadBinds('dbind', cPathz[ptData] + '/settings.ini'); |
|
304 end; |
|
305 |
|
306 |
235 procedure InitKbdKeyTable; |
307 procedure InitKbdKeyTable; |
236 var i, j, k, t: LongInt; |
308 var i, j, k, t: LongInt; |
237 s: string[15]; |
309 s: string[15]; |
238 begin |
310 begin |
239 //TODO in sdl13 this overrides some values (A and B) change indices to some other values at the back perhaps? |
311 KeyNames[cKeyMaxIndex ]:= 'mousel'; |
240 KeyNames[1]:= 'mousel'; |
312 KeyNames[cKeyMaxIndex - 1]:= 'mousem'; |
241 KeyNames[2]:= 'mousem'; |
313 KeyNames[cKeyMaxIndex - 2]:= 'mouser'; |
242 KeyNames[3]:= 'mouser'; |
314 KeyNames[cKeyMaxIndex - 3]:= 'wheelup'; |
243 KeyNames[4]:= 'wheelup'; |
315 KeyNames[cKeyMaxIndex - 4]:= 'wheeldown'; |
244 KeyNames[5]:= 'wheeldown'; |
316 |
245 |
317 for i:= 0 to cKeyMaxIndex - 5 do |
246 for i:= 6 to cKeyMaxIndex do |
|
247 begin |
|
248 s:= shortstring(sdl_getkeyname(i)); |
|
249 //WriteLnToConsole('uInputHandler - ' + IntToStr(i) + ': ' + s + ' ' + IntToStr(cKeyMaxIndex)); |
|
250 if s = 'unknown key' then KeyNames[i]:= '' |
|
251 else |
|
252 begin |
318 begin |
|
319 s:= shortstring(SDL_GetScancodeName(TSDL_Scancode(i))); |
|
320 |
253 for t:= 1 to Length(s) do |
321 for t:= 1 to Length(s) do |
254 if s[t] = ' ' then |
322 if s[t] = ' ' then |
255 s[t]:= '_'; |
323 s[t]:= '_'; |
256 KeyNames[i]:= LowerCase(s) |
324 KeyNames[i]:= LowerCase(s) |
257 end; |
325 end; |
258 end; |
326 |
259 |
327 |
260 |
328 // get the size of keyboard array |
261 // get the size of keyboard array |
329 SDL_GetKeyboardState(@k); |
262 SDL_GetKeyState(@k); |
330 |
263 |
331 // Controller(s) |
264 // Controller(s) |
332 for j:= 0 to Pred(ControllerNumControllers) do |
265 for j:= 0 to Pred(ControllerNumControllers) do |
|
266 begin |
|
267 for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
268 begin |
333 begin |
269 keynames[k + 0]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'u'; |
334 for i:= 0 to Pred(ControllerNumAxes[j]) do |
270 keynames[k + 1]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'd'; |
335 begin |
271 inc(k, 2); |
336 KeyNames[k + 0]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'u'; |
|
337 KeyNames[k + 1]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'd'; |
|
338 inc(k, 2); |
|
339 end; |
|
340 for i:= 0 to Pred(ControllerNumHats[j]) do |
|
341 begin |
|
342 KeyNames[k + 0]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'u'; |
|
343 KeyNames[k + 1]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'r'; |
|
344 KeyNames[k + 2]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'd'; |
|
345 KeyNames[k + 3]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'l'; |
|
346 inc(k, 4); |
|
347 end; |
|
348 for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
349 begin |
|
350 KeyNames[k]:= 'j' + IntToStr(j) + 'b' + IntToStr(i); |
|
351 inc(k, 1); |
|
352 end; |
272 end; |
353 end; |
273 for i:= 0 to Pred(ControllerNumHats[j]) do |
354 |
274 begin |
355 InitDefaultBinds |
275 keynames[k + 0]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'u'; |
356 end; |
276 keynames[k + 1]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'r'; |
357 |
277 keynames[k + 2]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'd'; |
358 |
278 keynames[k + 3]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'l'; |
359 |
279 inc(k, 4); |
360 {$IFNDEF MOBILE} |
280 end; |
|
281 for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
282 begin |
|
283 keynames[k]:= 'j' + IntToStr(j) + 'b' + IntToStr(i); |
|
284 inc(k, 1); |
|
285 end; |
|
286 end; |
|
287 |
|
288 DefaultBinds[KeyNameToCode('escape')]:= 'quit'; |
|
289 DefaultBinds[KeyNameToCode(_S'`')]:= 'history'; |
|
290 DefaultBinds[KeyNameToCode('delete')]:= 'rotmask'; |
|
291 |
|
292 //numpad |
|
293 //DefaultBinds[265]:= '+volup'; |
|
294 //DefaultBinds[256]:= '+voldown'; |
|
295 |
|
296 DefaultBinds[KeyNameToCode(_S'0')]:= '+volup'; |
|
297 DefaultBinds[KeyNameToCode(_S'9')]:= '+voldown'; |
|
298 DefaultBinds[KeyNameToCode(_S'8')]:= 'mute'; |
|
299 DefaultBinds[KeyNameToCode(_S'c')]:= 'capture'; |
|
300 DefaultBinds[KeyNameToCode(_S'r')]:= 'record'; |
|
301 DefaultBinds[KeyNameToCode(_S'h')]:= 'findhh'; |
|
302 DefaultBinds[KeyNameToCode(_S'p')]:= 'pause'; |
|
303 DefaultBinds[KeyNameToCode(_S's')]:= '+speedup'; |
|
304 DefaultBinds[KeyNameToCode(_S't')]:= 'chat'; |
|
305 DefaultBinds[KeyNameToCode(_S'y')]:= 'confirm'; |
|
306 |
|
307 DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
|
308 DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomin'; |
|
309 DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomout'; |
|
310 |
|
311 DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
|
312 |
|
313 |
|
314 DefaultBinds[KeyNameToCode('mousel')]:= '/put'; |
|
315 DefaultBinds[KeyNameToCode('mouser')]:= 'ammomenu'; |
|
316 DefaultBinds[KeyNameToCode('backspace')]:= 'hjump'; |
|
317 DefaultBinds[KeyNameToCode('tab')]:= 'switch'; |
|
318 DefaultBinds[KeyNameToCode('return')]:= 'ljump'; |
|
319 DefaultBinds[KeyNameToCode('space')]:= '+attack'; |
|
320 DefaultBinds[KeyNameToCode('up')]:= '+up'; |
|
321 DefaultBinds[KeyNameToCode('down')]:= '+down'; |
|
322 DefaultBinds[KeyNameToCode('left')]:= '+left'; |
|
323 DefaultBinds[KeyNameToCode('right')]:= '+right'; |
|
324 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise'; |
|
325 |
|
326 |
|
327 DefaultBinds[KeyNameToCode('j0a0u')]:= '+left'; |
|
328 DefaultBinds[KeyNameToCode('j0a0d')]:= '+right'; |
|
329 DefaultBinds[KeyNameToCode('j0a1u')]:= '+up'; |
|
330 DefaultBinds[KeyNameToCode('j0a1d')]:= '+down'; |
|
331 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+char(i+48); |
|
332 for i:= 1 to 5 do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i); |
|
333 |
|
334 loadBinds('dbind', cPathz[ptConfig] + '/settings.ini'); |
|
335 end; |
|
336 |
|
337 procedure SetBinds(var binds: TBinds); |
361 procedure SetBinds(var binds: TBinds); |
338 {$IFNDEF MOBILE} |
|
339 var |
362 var |
340 t: LongInt; |
363 t: LongInt; |
341 {$ENDIF} |
364 begin |
342 begin |
|
343 {$IFDEF MOBILE} |
|
344 binds:= binds; // avoid hint |
|
345 CurrentBinds:= DefaultBinds; |
|
346 {$ELSE} |
|
347 for t:= 0 to cKbdMaxIndex do |
365 for t:= 0 to cKbdMaxIndex do |
348 if (CurrentBinds[t] <> binds[t]) and tkbd[t] then |
366 if (CurrentBinds[t] <> binds[t]) and tkbd[t] then |
349 ProcessKey(t, False); |
367 ProcessKey(t, False); |
350 |
368 |
351 CurrentBinds:= binds; |
369 CurrentBinds:= binds; |
|
370 end; |
|
371 {$ELSE} |
|
372 procedure SetBinds(var binds: TBinds); |
|
373 begin |
|
374 binds:= binds; // avoid hint |
|
375 CurrentBinds:= DefaultBinds; |
|
376 end; |
352 {$ENDIF} |
377 {$ENDIF} |
353 end; |
|
354 |
378 |
355 procedure SetDefaultBinds; |
379 procedure SetDefaultBinds; |
356 begin |
380 begin |
357 CurrentBinds:= DefaultBinds; |
381 CurrentBinds:= DefaultBinds; |
358 end; |
382 end; |