hedgewars/uKeys.pas
changeset 3697 d5b30d6373fc
parent 3663 8c28abf427f5
child 3971 5c82ee165ed5
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    69     upKey: boolean;
    69     upKey: boolean;
    70     downKey: boolean;
    70     downKey: boolean;
    71     rightKey: boolean;
    71     rightKey: boolean;
    72     leftKey: boolean;
    72     leftKey: boolean;
    73     preciseKey: boolean;
    73     preciseKey: boolean;
    74     
    74 
    75     backspaceKey: boolean;
    75     backspaceKey: boolean;
    76     spaceKey: boolean;
    76     spaceKey: boolean;
    77     enterKey: boolean;
    77     enterKey: boolean;
    78     tabKey: boolean;
    78     tabKey: boolean;
    79     
    79 
    80     chatAction: boolean;
    80     chatAction: boolean;
    81     pauseAction: boolean;
    81     pauseAction: boolean;
    82     
    82 
    83 {$IFDEF IPHONEOS}    
    83 {$IFDEF IPHONEOS}
    84 procedure setiPhoneBinds;
    84 procedure setiPhoneBinds;
    85 {$ENDIF}
    85 {$ENDIF}
    86 {$ENDIF}
    86 {$ENDIF}
    87 implementation
    87 implementation
    88 uses uTeams, uConsole, uMisc;
    88 uses uTeams, uConsole, uMisc;
    89 //const KeyNumber = 1024;
    89 //const KeyNumber = 1024;
    90 
    90 
    91 var tkbd, tkbdn: TKeyboardState;
    91 var tkbd, tkbdn: TKeyboardState;
    92     KeyNames: array [0..cKeyMaxIndex] of string[15];
    92     KeyNames: array [0..cKeyMaxIndex] of string[15];
    93     
    93 
    94 function KeyNameToCode(name: shortstring): word;
    94 function KeyNameToCode(name: shortstring): word;
    95 var code: Word;
    95 var code: Word;
    96 begin
    96 begin
    97     code:= cKeyMaxIndex;
    97     code:= cKeyMaxIndex;
    98     while (code > 0) and (KeyNames[code] <> name) do dec(code);
    98     while (code > 0) and (KeyNames[code] <> name) do dec(code);
   245         begin
   245         begin
   246         tkbdn[k]:= ControllerButtons[j][i];
   246         tkbdn[k]:= ControllerButtons[j][i];
   247         inc(k, 1);
   247         inc(k, 1);
   248         end;
   248         end;
   249     end;
   249     end;
   250     
   250 
   251 for t:= 0 to cKeyMaxIndex do
   251 for t:= 0 to cKeyMaxIndex do
   252     tkbd[i]:= tkbdn[i]
   252     tkbd[i]:= tkbdn[i]
   253 end;
   253 end;
   254 
   254 
   255 procedure InitKbdKeyTable;
   255 procedure InitKbdKeyTable;
   384     tkbdn[13]:= ord(enterKey);
   384     tkbdn[13]:= ord(enterKey);
   385     tkbdn[32]:= ord(spaceKey);
   385     tkbdn[32]:= ord(spaceKey);
   386 
   386 
   387     tkbdn[44]:= ord(chatAction);
   387     tkbdn[44]:= ord(chatAction);
   388     tkbdn[55]:= ord(pauseAction);
   388     tkbdn[55]:= ord(pauseAction);
   389     
   389 
   390     // set to false the keys that only need one stoke
   390     // set to false the keys that only need one stoke
   391     leftClick:= false;
   391     leftClick:= false;
   392     middleClick:= false;
   392     middleClick:= false;
   393     rightClick:= false;
   393     rightClick:= false;
   394 
   394 
   395     tabKey:= false;
   395     tabKey:= false;
   396     enterKey:= false;
   396     enterKey:= false;
   397     backspaceKey:= false;
   397     backspaceKey:= false;
   398     
   398 
   399     chatAction:= false;
   399     chatAction:= false;
   400     pauseAction:= false;
   400     pauseAction:= false;
   401 end;
   401 end;
   402 {$ENDIF}
   402 {$ENDIF}
   403 
   403 
   406     tkbd[13]:= 1;
   406     tkbd[13]:= 1;
   407     tkbd[271]:= 1;
   407     tkbd[271]:= 1;
   408 end;
   408 end;
   409 
   409 
   410 var Controller: array [0..5] of PSDL_Joystick;
   410 var Controller: array [0..5] of PSDL_Joystick;
   411     
   411 
   412 procedure ControllerInit;
   412 procedure ControllerInit;
   413 var i, j: Integer;
   413 var i, j: Integer;
   414 begin
   414 begin
   415 ControllerEnabled:= 0;
   415 ControllerEnabled:= 0;
   416 {$IFDEF IPHONEOS}
   416 {$IFDEF IPHONEOS}
   440             WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j]));
   440             WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j]));
   441             //WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j]));
   441             //WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j]));
   442             WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j]));
   442             WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j]));
   443             WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j]));
   443             WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j]));
   444             ControllerEnabled:= 1;
   444             ControllerEnabled:= 1;
   445             
   445 
   446             if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20;
   446             if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20;
   447             //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20;
   447             //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20;
   448             if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20;
   448             if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20;
   449             if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20;
   449             if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20;
   450             
   450 
   451             // reset all buttons/axes
   451             // reset all buttons/axes
   452             for i:= 0 to pred(ControllerNumAxes[j]) do
   452             for i:= 0 to pred(ControllerNumAxes[j]) do
   453                 ControllerAxes[j][i]:= 0;
   453                 ControllerAxes[j][i]:= 0;
   454             (*for i:= 0 to pred(ControllerNumBalls[j]) do
   454             (*for i:= 0 to pred(ControllerNumBalls[j]) do
   455                 begin
   455                 begin
   463             end;
   463             end;
   464         end;
   464         end;
   465     // enable event generation/controller updating
   465     // enable event generation/controller updating
   466     SDL_JoystickEventState(1);
   466     SDL_JoystickEventState(1);
   467     end
   467     end
   468 else    
   468 else
   469     WriteLnToConsole('Not using any game controller');
   469     WriteLnToConsole('Not using any game controller');
   470 end;
   470 end;
   471 
   471 
   472 procedure ControllerClose;
   472 procedure ControllerClose;
   473 var j: Integer;
   473 var j: Integer;
   498     wheelUp:= false;
   498     wheelUp:= false;
   499     wheelDown:= false;
   499     wheelDown:= false;
   500     coeff:= 5;
   500     coeff:= 5;
   501 {$IFDEF HWLIBRARY}
   501 {$IFDEF HWLIBRARY}
   502     // this function is called by HW_allKeysUp so be careful
   502     // this function is called by HW_allKeysUp so be careful
   503     
   503 
   504     // mouse emulation
   504     // mouse emulation
   505     leftClick:= false;
   505     leftClick:= false;
   506     middleClick:= false;
   506     middleClick:= false;
   507     rightClick:= false;
   507     rightClick:= false;
   508 
   508