hedgewars/uInputHandler.pas
branchwebgl
changeset 8833 c13ebed437cb
parent 8446 c18ba8726f5a
parent 8746 55539c550c33
child 9127 e350500c4edb
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
    56     RALT   = $1000;
    56     RALT   = $1000;
    57     LCTRL  = $2000;
    57     LCTRL  = $2000;
    58     RCTRL  = $4000;
    58     RCTRL  = $4000;
    59 
    59 
    60 var tkbd: array[0..cKbdMaxIndex] of boolean;
    60 var tkbd: array[0..cKbdMaxIndex] of boolean;
    61     quitKeyCode, closeKeyCode: Byte;
       
    62     KeyNames: array [0..cKeyMaxIndex] of string[15];
    61     KeyNames: array [0..cKeyMaxIndex] of string[15];
    63     CurrentBinds: TBinds;
    62     CurrentBinds: TBinds;
    64     ControllerNumControllers: Integer;
    63     ControllerNumControllers: Integer;
    65     ControllerEnabled: Integer;
    64     ControllerEnabled: Integer;
    66     ControllerNumAxes: array[0..5] of Integer;
    65     ControllerNumAxes: array[0..5] of Integer;
   136 Trusted:= (CurrentTeam <> nil)
   135 Trusted:= (CurrentTeam <> nil)
   137           and (not CurrentTeam^.ExtDriven)
   136           and (not CurrentTeam^.ExtDriven)
   138           and (CurrentHedgehog^.BotLevel = 0);
   137           and (CurrentHedgehog^.BotLevel = 0);
   139 
   138 
   140 // ctrl/cmd + q to close engine and frontend
   139 // ctrl/cmd + q to close engine and frontend
   141 if(KeyDown and (code = quitKeyCode)) then
   140 if(KeyDown and (code = SDLK_q)) then
   142     begin
   141     begin
   143 {$IFDEF DARWIN}
   142 {$IFDEF DARWIN}
   144     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
   143     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
   145 {$ELSE}
   144 {$ELSE}
   146     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
   145     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
   147 {$ENDIF}
   146 {$ENDIF}
   148         ParseCommand('halt', true);
   147         ParseCommand('halt', true);
   149     end;
   148     end;
   150 
   149 
   151 // ctrl/cmd + w to close engine
   150 // ctrl/cmd + w to close engine
   152 if(KeyDown and (code = closeKeyCode)) then
   151 if(KeyDown and (code = SDLK_w)) then
   153     begin
   152     begin
   154 {$IFDEF DARWIN}
   153 {$IFDEF DARWIN}
   155     // on OS X it this is expected behaviour
   154     // on OS X it this is expected behaviour
   156     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
   155     if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then
   157 {$ELSE}
   156 {$ELSE}
   158     // on other systems use this shortcut only if the keys are not bound to any command
   157     // on other systems use this shortcut only if the keys are not bound to any command
   159     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
   158     if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then
   160         if ((CurrentBinds[KeyNameToCode('left_ctrl')] = '') or
   159         if ((CurrentBinds[KeyNameToCode('left_ctrl')] = '') or
   161             (CurrentBinds[KeyNameToCode('right_ctrl')] = '')) and
   160             (CurrentBinds[KeyNameToCode('right_ctrl')] = '')) and
   162             (CurrentBinds[closeKeyCode] = '') then
   161             (CurrentBinds[SDLK_w] = '') then
   163 {$ENDIF}
   162 {$ENDIF}
   164         ParseCommand('forcequit', true);
   163         ParseCommand('forcequit', true);
   165     end;
   164     end;
   166 
   165 
   167 if CurrentBinds[code][0] <> #0 then
   166 if CurrentBinds[code][0] <> #0 then
   240                 s[t]:= '_';
   239                 s[t]:= '_';
   241         KeyNames[i]:= LowerCase(s)
   240         KeyNames[i]:= LowerCase(s)
   242         end;
   241         end;
   243     end;
   242     end;
   244 
   243 
   245 quitKeyCode:= KeyNameToCode(_S'q');
       
   246 closeKeyCode:= KeyNameToCode(_S'w');
       
   247 
   244 
   248 // get the size of keyboard array
   245 // get the size of keyboard array
   249 SDL_GetKeyState(@k);
   246 SDL_GetKeyState(@k);
   250 
   247 
   251 // Controller(s)
   248 // Controller(s)