hedgewars/uKeys.pas
changeset 351 29bc9c36ad5f
parent 345 fa39c61be4de
child 371 731ad6d27bd1
equal deleted inserted replaced
350:c3ccec3834e8 351:29bc9c36ad5f
    41 var tkbd: TKeyboardState;
    41 var tkbd: TKeyboardState;
    42     KeyNames: array [0..cKeyMaxIndex] of string[15];
    42     KeyNames: array [0..cKeyMaxIndex] of string[15];
    43     DefaultBinds, CurrentBinds: TBinds;
    43     DefaultBinds, CurrentBinds: TBinds;
    44 
    44 
    45 function KeyNameToCode(name: string): word;
    45 function KeyNameToCode(name: string): word;
       
    46 var Result: Word;
    46 begin
    47 begin
    47 Result:= cKeyMaxIndex;
    48 Result:= cKeyMaxIndex;
    48 while (Result > 0) and (KeyNames[Result] <> name) do dec(Result)
    49 while (Result > 0) and (KeyNames[Result] <> name) do dec(Result);
       
    50 KeyNameToCode:= Result
    49 end;
    51 end;
    50 
    52 
    51 procedure ProcessKbd;
    53 procedure ProcessKbd;
    52 var  i: integer;
    54 var  i: integer;
    53      s: shortstring;
    55      s: shortstring;
    54      pkbd: PByteArray;
    56      pkbd: PByteArray;
    55      Trusted: boolean;
    57      Trusted: boolean;
    56 begin
    58 begin
    57 KbdKeyPressed:= false;
    59 KbdKeyPressed:= false;
    58 Trusted:= (CurrentTeam <> nil)
    60 Trusted:= (CurrentTeam <> nil)
    59           and (not CurrentTeam.ExtDriven)
    61           and (not CurrentTeam^.ExtDriven)
    60           and (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].BotLevel = 0);
    62           and (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].BotLevel = 0);
    61 
    63 
    62 pkbd:= SDL_GetKeyState(nil);
    64 pkbd:= SDL_GetKeyState(nil);
    63 i:= SDL_GetMouseState(nil, nil);
    65 i:= SDL_GetMouseState(nil, nil);
    64 pkbd^[1]:= (i and 1);
    66 pkbd^[1]:= (i and 1);
    65 pkbd^[2]:= ((i shr 1) and 1);
    67 pkbd^[2]:= ((i shr 1) and 1);
    73           if (pkbd^[i] <> 0)and(tkbd[i]  = 0) then ParseCommand(CurrentBinds[i], Trusted) else
    75           if (pkbd^[i] <> 0)and(tkbd[i]  = 0) then ParseCommand(CurrentBinds[i], Trusted) else
    74           if (pkbd^[i] =  0)and(tkbd[i] <> 0) then
    76           if (pkbd^[i] =  0)and(tkbd[i] <> 0) then
    75              begin
    77              begin
    76              s:= CurrentBinds[i];
    78              s:= CurrentBinds[i];
    77              s[1]:= '-';
    79              s[1]:= '-';
    78              ParseCommand(s)
    80              ParseCommand(s, true)
    79              end;
    81              end;
    80           end else
    82           end else
    81           if (tkbd[i] = 0) and (pkbd^[i] <> 0) then ParseCommand(CurrentBinds[i], Trusted);
    83           if (tkbd[i] = 0) and (pkbd^[i] <> 0) then ParseCommand(CurrentBinds[i], Trusted);
    82        tkbd[i]:= pkbd^[i]
    84        tkbd[i]:= pkbd^[i]
    83        end
    85        end