hedgewars/uKeys.pas
changeset 6942 11f52445e8cd
parent 6917 4889c2b779b4
equal deleted inserted replaced
6941:228c0ab239f1 6942:11f52445e8cd
    44 
    44 
    45 implementation
    45 implementation
    46 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
    46 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
    47 
    47 
    48 var tkbd, tkbdn: TKeyboardState;
    48 var tkbd, tkbdn: TKeyboardState;
       
    49     quitKeyCode: Byte;
    49     KeyNames: array [0..cKeyMaxIndex] of string[15];
    50     KeyNames: array [0..cKeyMaxIndex] of string[15];
       
    51     
    50 
    52 
    51 function KeyNameToCode(name: shortstring): word;
    53 function KeyNameToCode(name: shortstring): word;
    52 var code: Word;
    54 var code: Word;
    53 begin
    55 begin
    54     name:= LowerCase(name);
    56     name:= LowerCase(name);
   103         inc(k, 1);
   105         inc(k, 1);
   104         end;
   106         end;
   105     end;
   107     end;
   106 {$ENDIF}
   108 {$ENDIF}
   107 
   109 
   108 
   110 end;
   109 //TODO reimplement this
   111 
       
   112 
       
   113 procedure ProcessKey(code: LongInt; KeyDown: boolean);
       
   114 var
       
   115     Trusted: boolean;
       
   116     s      : string;
       
   117 begin
       
   118 hideAmmoMenu:= false;
       
   119 Trusted:= (CurrentTeam <> nil)
       
   120           and (not CurrentTeam^.ExtDriven)
       
   121           and (CurrentHedgehog^.BotLevel = 0);
       
   122 
       
   123 tkbdn[code]:= ord(KeyDown);
       
   124 
   110 // ctrl/cmd + q to close engine and frontend
   125 // ctrl/cmd + q to close engine and frontend
       
   126 if(KeyDown and (code = quitKeyCode)) then
       
   127     begin
   111 {$IFDEF DARWIN}
   128 {$IFDEF DARWIN}
   112     if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
   129     if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
   113 {$ELSE}
   130 {$ELSE}
   114     if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
   131     if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
   115 {$ENDIF}
   132 {$ENDIF}
   116     begin
   133         ParseCommand('halt', true);    
   117         if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true)
   134     end;
   118     end;
       
   119 end;
       
   120 
       
   121 
       
   122 procedure ProcessKey(code: LongInt; KeyDown: boolean);
       
   123 var
       
   124     Trusted: boolean;
       
   125     s      : string;
       
   126 begin
       
   127 hideAmmoMenu:= false;
       
   128 Trusted:= (CurrentTeam <> nil)
       
   129           and (not CurrentTeam^.ExtDriven)
       
   130           and (CurrentHedgehog^.BotLevel = 0);
       
   131 
       
   132 tkbdn[code]:= ord(KeyDown);
       
   133 
   135 
   134 if CurrentBinds[code][0] <> #0 then
   136 if CurrentBinds[code][0] <> #0 then
   135     begin
   137     begin
   136     if (code > 3) and (tkbdn[code] <> 0) and not ((CurrentBinds[code] = 'put') or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) then hideAmmoMenu:= true;
   138     if (code > 3) and (tkbdn[code] <> 0) and not ((CurrentBinds[code] = 'put') or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) then hideAmmoMenu:= true;
   137     if (tkbd[code] = 0) and (tkbdn[code] <> 0) then
   139     if (tkbd[code] = 0) and (tkbdn[code] <> 0) then
   253                 s[t]:= '_';
   255                 s[t]:= '_';
   254         KeyNames[i]:= LowerCase(s)
   256         KeyNames[i]:= LowerCase(s)
   255         end;
   257         end;
   256     end;
   258     end;
   257 
   259 
   258 //for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]);
   260 quitKeyCode:= KeyNameToCode('q');
   259 
   261 
   260 // get the size of keyboard array
   262 // get the size of keyboard array
   261 SDL_GetKeyState(@k);
   263 SDL_GetKeyState(@k);
   262 
   264 
   263 // Controller(s)
   265 // Controller(s)