hedgewars/uKeys.pas
changeset 2579 e5e4ebf528b5
parent 2567 02ff5f9510b5
child 2580 aeccc8f51d3f
equal deleted inserted replaced
2578:ec8e69b23097 2579:e5e4ebf528b5
    50 upKey: boolean = false;
    50 upKey: boolean = false;
    51 downKey: boolean = false;
    51 downKey: boolean = false;
    52 rightKey: boolean = false;
    52 rightKey: boolean = false;
    53 leftKey: boolean = false;
    53 leftKey: boolean = false;
    54 
    54 
       
    55 backspaceKey: boolean = false;
    55 spaceKey: boolean = false;
    56 spaceKey: boolean = false;
    56 enterKey: boolean = false;
    57 enterKey: boolean = false;
       
    58 isAttacking:boolean = false;
       
    59 
    57 {$ENDIF}
    60 {$ENDIF}
    58 	ControllerNumControllers: Integer;
    61 	ControllerNumControllers: Integer;
    59     ControllerEnabled: Integer;
    62     ControllerEnabled: Integer;
    60     ControllerNumAxes: array[0..5] of Integer;
    63     ControllerNumAxes: array[0..5] of Integer;
    61     //ControllerNumBalls: array[0..5] of Integer;
    64     //ControllerNumBalls: array[0..5] of Integer;
   103 {$ELSE}
   106 {$ELSE}
   104 pkbd := SDL_GetKeyState(@j);
   107 pkbd := SDL_GetKeyState(@j);
   105 k    := SDL_GetMouseState(nil, nil);
   108 k    := SDL_GetMouseState(nil, nil);
   106 {$ENDIF}
   109 {$ENDIF}
   107 
   110 
       
   111 {$IFNDEF IPHONEOS}
   108 for i:= 6 to pred(j) do // first 6 will be overwritten
   112 for i:= 6 to pred(j) do // first 6 will be overwritten
   109 	tkbdn[i]:= pkbd^[i];
   113 	tkbdn[i]:= pkbd^[i];
       
   114 {$ENDIF}
   110 
   115 
   111 // mouse buttons
   116 // mouse buttons
   112 {$IFDEF DARWIN}
   117 {$IFDEF DARWIN}
   113 tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
   118 tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
   114 tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
   119 tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
   129 tkbdn[3]:= ord(rightClick);
   134 tkbdn[3]:= ord(rightClick);
   130 leftClick:= false;
   135 leftClick:= false;
   131 middleClick:= false;
   136 middleClick:= false;
   132 rightClick:= false;
   137 rightClick:= false;
   133 
   138 
   134 {*
       
   135 //sdl1.3 for these keys is messed up
   139 //sdl1.3 for these keys is messed up
   136 tkbdn[273]:= ord(upKey);
   140 //tkbdn[MYCONST]:= ord(upKey);
   137 tkbdn[274]:= ord(downKey);
   141 //tkbdn[MYCONST + 1]:= ord(downKey);
   138 tkbdn[275]:= ord(rightKey);
   142 //tkbdn[MYCONST + 2]:= ord(rightKey);
   139 tkbdn[276]:= ord(leftKey);
   143 //tkbdn[MYCONST + 3]:= ord(leftKey);
   140 
   144 
       
   145 tkbdn[ 8]:= ord(backspaceKey);
       
   146 tkbdn[13]:= ord(enterKey);
   141 tkbdn[32]:= ord(spaceKey);
   147 tkbdn[32]:= ord(spaceKey);
   142 tkbdn[13]:= ord(enterKey);
       
   143 
   148 
   144 upKey:= false;
   149 upKey:= false;
   145 downKey:= false;
   150 downKey:= false;
   146 rightKey:= false;
   151 rightKey:= false;
   147 leftKey:= false;
   152 leftKey:= false;
   148 
   153 
   149 spaceKey:= false;
   154 if isAttacking = false then spaceKey:= false;
   150 enterKey:= false;
   155 enterKey:= false;
   151 *}
   156 backspaceKey:= false;
       
   157 
   152 {$ENDIF}
   158 {$ENDIF}
   153 
   159 
   154 // Controller(s)
   160 // Controller(s)
   155 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   161 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   156 for j:= 0 to Pred(ControllerNumControllers) do
   162 for j:= 0 to Pred(ControllerNumControllers) do
   193 	tkbd[i]:= tkbdn[i]
   199 	tkbd[i]:= tkbdn[i]
   194 	end
   200 	end
   195 end;
   201 end;
   196 
   202 
   197 procedure ResetKbd;
   203 procedure ResetKbd;
   198 var i, j, k, t: LongInt;
   204 var i, j, k, t,tmp: LongInt;
   199     pkbd: PByteArray;
   205     pkbd: PByteArray;
   200 begin
   206 begin
   201 
   207 
   202 {$IFDEF SDL13}
   208 {$IFDEF SDL13}
   203 pkbd:= SDL_GetKeyboardState(@j);
   209 pkbd:= SDL_GetKeyboardState(@j);
   206 pkbd:= SDL_GetKeyState(@j);
   212 pkbd:= SDL_GetKeyState(@j);
   207 k:= SDL_GetMouseState(nil, nil);
   213 k:= SDL_GetMouseState(nil, nil);
   208 {$ENDIF}
   214 {$ENDIF}
   209 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
   215 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
   210 
   216 
       
   217 {$IFNDEF IPHONEOS}
   211 for i:= 1 to pred(j) do
   218 for i:= 1 to pred(j) do
   212 	tkbdn[i]:= pkbd^[i];
   219 	tkbdn[i]:= pkbd^[i];
       
   220 {$ENDIF}
   213 
   221 
   214 // mouse buttons
   222 // mouse buttons
   215 {$IFDEF DARWIN}
   223 {$IFDEF DARWIN}
   216 tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
   224 tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
   217 tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
   225 tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
   232 tkbdn[3]:= ord(rightClick);
   240 tkbdn[3]:= ord(rightClick);
   233 leftClick:= false;
   241 leftClick:= false;
   234 middleClick:= false;
   242 middleClick:= false;
   235 rightClick:= false;
   243 rightClick:= false;
   236 
   244 
   237 {*
   245 //sdl1.3 for these keys is messed up
   238 tkbdn[273]:= ord(upKey);
   246 //tkbdn[MYCONST]:= ord(upKey);
   239 tkbdn[274]:= ord(downKey);
   247 //tkbdn[MYCONST + 1]:= ord(downKey);
   240 tkbdn[275]:= ord(rightKey);
   248 //tkbdn[MYCONST + 2]:= ord(rightKey);
   241 tkbdn[276]:= ord(leftKey);
   249 //tkbdn[MYCONST + 3]:= ord(leftKey);
   242 
   250 
       
   251 tkbdn[ 8]:= ord(backspaceKey);
       
   252 tkbdn[13]:= ord(enterKey);
   243 tkbdn[32]:= ord(spaceKey);
   253 tkbdn[32]:= ord(spaceKey);
   244 tkbdn[13]:= ord(enterKey);
       
   245 
   254 
   246 upKey:= false;
   255 upKey:= false;
   247 downKey:= false;
   256 downKey:= false;
   248 rightKey:= false;
   257 rightKey:= false;
   249 leftKey:= false;
   258 leftKey:= false;
   250 
   259 
   251 spaceKey:= false;
   260 if isAttacking = false then spaceKey:= false;
   252 enterKey:= false;
   261 enterKey:= false;
   253 *}
   262 backspaceKey:= false;
   254 {$ENDIF}
   263 {$ENDIF}
   255 
   264 
   256 // Controller(s)
   265 // Controller(s)
   257 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   266 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   258 for j:= 0 to Pred(ControllerNumControllers) do
   267 for j:= 0 to Pred(ControllerNumControllers) do
   332 		begin
   341 		begin
   333 		keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i);
   342 		keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i);
   334 		inc(k, 1);
   343 		inc(k, 1);
   335 		end;
   344 		end;
   336 	end;
   345 	end;
       
   346 {$IFDEF IPHONEOS}
       
   347 
       
   348 DefaultBinds[  3]:= 'ammomenu';
       
   349 DefaultBinds[  8]:= 'hjump';
       
   350 DefaultBinds[ 13]:= 'ljump';
       
   351 DefaultBinds[ 32]:= '+attack';
       
   352 
       
   353 {$ENDIF}
   337 	
   354 	
   338 DefaultBinds[ 27]:= 'quit';
   355 DefaultBinds[ 27]:= 'quit';
   339 DefaultBinds[ 96]:= 'history';
   356 DefaultBinds[ 96]:= 'history';
   340 DefaultBinds[127]:= 'rotmask';
   357 DefaultBinds[127]:= 'rotmask';
   341 
   358