hedgewars/uKeys.pas
changeset 161 d8870bbf960e
parent 109 ab0340f580c2
child 167 805fa9a27e9e
equal deleted inserted replaced
160:207f520b9e83 161:d8870bbf960e
    39 procedure ProcessKbd;
    39 procedure ProcessKbd;
    40 procedure ResetKbd;
    40 procedure ResetKbd;
    41 procedure ProcessKbdDemo;
    41 procedure ProcessKbdDemo;
    42 procedure InitKbdKeyTable;
    42 procedure InitKbdKeyTable;
    43 
    43 
       
    44 var KbdKeyPressed: boolean;
       
    45 
    44 implementation
    46 implementation
    45 uses SDLh, uTeams, uConsole, uConsts, uMisc;
    47 uses SDLh, uTeams, uConsole, uConsts, uMisc;
    46 const KeyNumber = 1024;
    48 const KeyNumber = 1024;
    47 type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
    49 type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
    48 var tkbd: TKeyboardState;
    50 var tkbd: TKeyboardState;
    49     KeyNames: array [0..cKeyMaxIndex] of string[15];
    51     KeyNames: array [0..cKeyMaxIndex] of string[15];
    50 
    52 
    51 function KeyNameToCode(name: string): word;
    53 function KeyNameToCode(name: string): word;
    52 begin
    54 begin
    53 Result:= cKeyMaxIndex;
    55 Result:= cKeyMaxIndex;
    54 while (Result>0)and(KeyNames[Result]<>name) do dec(Result)
    56 while (Result > 0) and (KeyNames[Result] <> name) do dec(Result)
    55 end;
    57 end;
    56 
    58 
    57 procedure ProcessKbd;
    59 procedure ProcessKbd;
    58 var  i: integer;
    60 var  i: integer;
    59      s: shortstring;
    61      s: shortstring;
    61 begin
    63 begin
    62 if (CurrentTeam = nil)
    64 if (CurrentTeam = nil)
    63    or (GameState = gsConsole)
    65    or (GameState = gsConsole)
    64    or (CurrentTeam.ExtDriven)
    66    or (CurrentTeam.ExtDriven)
    65    or (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].BotLevel <> 0) then exit;
    67    or (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].BotLevel <> 0) then exit;
       
    68 
       
    69 KbdKeyPressed:= false;
    66 pkbd:= SDL_GetKeyState(nil);
    70 pkbd:= SDL_GetKeyState(nil);
    67 i:= SDL_GetMouseState(nil, nil);
    71 i:= SDL_GetMouseState(nil, nil);
    68 pkbd^[1]:= (i and 1);
    72 pkbd^[1]:= (i and 1);
    69 pkbd^[2]:= ((i shl 1) and 1);
    73 pkbd^[2]:= ((i shr 1) and 1);
    70 pkbd^[3]:= ((i shl 2) and 1);
    74 pkbd^[3]:= ((i shr 2) and 1);
    71 for i:= 1 to cKeyMaxIndex do
    75 for i:= 1 to cKeyMaxIndex do
    72     if CurrentTeam.Aliases[i][0]<>#0 then
    76     if CurrentTeam.Aliases[i][0] <> #0 then
    73        begin
    77       begin
    74        if CurrentTeam.Aliases[i][1]='+' then
    78       if (i > 3) and (pkbd^[i] <> 0) then KbdKeyPressed:= true;
       
    79       if CurrentTeam.Aliases[i][1] = '+' then
    75           begin
    80           begin
    76           if (pkbd^[i] <> 0)and(tkbd[i]  = 0) then ParseCommand(CurrentTeam.Aliases[i]) else
    81           if (pkbd^[i] <> 0)and(tkbd[i]  = 0) then ParseCommand(CurrentTeam.Aliases[i]) else
    77           if (pkbd^[i] =  0)and(tkbd[i] <> 0) then
    82           if (pkbd^[i] =  0)and(tkbd[i] <> 0) then
    78              begin
    83              begin
    79              s:= CurrentTeam.Aliases[i];
    84              s:= CurrentTeam.Aliases[i];