hedgewars/uInputHandler.pas
changeset 7869 5dd2c047c96f
parent 7848 775a72905708
child 7870 e031c963c5df
equal deleted inserted replaced
7868:bfbc6aa87b7c 7869:5dd2c047c96f
    55     RALT   = $1000;
    55     RALT   = $1000;
    56     LCTRL  = $2000;
    56     LCTRL  = $2000;
    57     RCTRL  = $4000; 
    57     RCTRL  = $4000; 
    58 
    58 
    59 var tkbd: array[0..cKbdMaxIndex] of boolean;
    59 var tkbd: array[0..cKbdMaxIndex] of boolean;
    60     quitKeyCode: Byte;
    60     quitKeyCode, closeKeyCode: Byte;
    61     KeyNames: array [0..cKeyMaxIndex] of string[15];
    61     KeyNames: array [0..cKeyMaxIndex] of string[15];
    62     CurrentBinds: TBinds;
    62     CurrentBinds: TBinds;
    63 
    63 
    64 function  KeyNameToCode(name: shortstring): LongInt; inline;
    64 function  KeyNameToCode(name: shortstring): LongInt; inline;
    65 begin
    65 begin
   132 {$IFDEF DARWIN}
   132 {$IFDEF DARWIN}
   133     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
   133     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
   134 {$ELSE}
   134 {$ELSE}
   135     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
   135     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
   136 {$ENDIF}
   136 {$ENDIF}
   137         ParseCommand('halt', true);    
   137         ParseCommand('halt', true);
       
   138     end;
       
   139 
       
   140 // ctrl/cmd + w to close engine
       
   141 if(KeyDown and (code = closeKeyCode)) then
       
   142     begin
       
   143 {$IFDEF DARWIN}
       
   144     // on OS X it this is expected behaviour
       
   145     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
       
   146 {$ELSE}
       
   147     // on other systems use this shortcut only if the keys are not bound to any command
       
   148     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
       
   149         if ((CurrentBinds([KeyNameToCode('left_ctrl')]:= '') or
       
   150              CurrentBinds([KeyNameToCode('right_ctrl')]:= '')) and
       
   151              CurrentBinds([closeKeyCode]:= '') then
       
   152 {$ENDIF}
       
   153         ParseCommand('forcequit', true);
   138     end;
   154     end;
   139 
   155 
   140 if CurrentBinds[code][0] <> #0 then
   156 if CurrentBinds[code][0] <> #0 then
   141     begin
   157     begin
   142     if (code > 3) and KeyDown 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;
   158     if (code > 3) and KeyDown 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;
   214         KeyNames[i]:= LowerCase(s)
   230         KeyNames[i]:= LowerCase(s)
   215         end;
   231         end;
   216     end;
   232     end;
   217 
   233 
   218 quitKeyCode:= KeyNameToCode(_S'q');
   234 quitKeyCode:= KeyNameToCode(_S'q');
       
   235 closeKeyCode:= KeyNameToCode(_S'w');
   219 
   236 
   220 // get the size of keyboard array
   237 // get the size of keyboard array
   221 SDL_GetKeyState(@k);
   238 SDL_GetKeyState(@k);
   222 
   239 
   223 // Controller(s)
   240 // Controller(s)