hedgewars/uKeys.pas
changeset 2567 02ff5f9510b5
parent 2438 6df2e58b6ab2
child 2579 e5e4ebf528b5
equal deleted inserted replaced
2565:54296af65fe9 2567:02ff5f9510b5
    20 interface
    20 interface
    21 uses uConsts;
    21 uses uConsts;
    22 {$INCLUDE options.inc}
    22 {$INCLUDE options.inc}
    23 
    23 
    24 type TBinds = array[0..cKeyMaxIndex] of shortstring;
    24 type TBinds = array[0..cKeyMaxIndex] of shortstring;
    25 
    25 type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
    26 function KeyNameToCode(name: string): word;
    26 
       
    27 function  KeyNameToCode(name: string): word;
    27 procedure ProcessKbd;
    28 procedure ProcessKbd;
    28 procedure ResetKbd;
    29 procedure ResetKbd;
    29 procedure FreezeEnterKey;
    30 procedure FreezeEnterKey;
    30 procedure InitKbdKeyTable;
    31 procedure InitKbdKeyTable;
    31 
    32 
    39 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
    40 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
    40 
    41 
    41 var hideAmmoMenu: boolean;
    42 var hideAmmoMenu: boolean;
    42 	wheelUp: boolean = false;
    43 	wheelUp: boolean = false;
    43 	wheelDown: boolean = false;
    44 	wheelDown: boolean = false;
    44 
    45 {$IFDEF IPHONEOS}
       
    46         leftClick: boolean = false;
       
    47         middleClick: boolean = false;
       
    48         rightClick: boolean = false;
       
    49 
       
    50 upKey: boolean = false;
       
    51 downKey: boolean = false;
       
    52 rightKey: boolean = false;
       
    53 leftKey: boolean = false;
       
    54 
       
    55 spaceKey: boolean = false;
       
    56 enterKey: boolean = false;
       
    57 {$ENDIF}
    45 	ControllerNumControllers: Integer;
    58 	ControllerNumControllers: Integer;
    46     ControllerEnabled: Integer;
    59     ControllerEnabled: Integer;
    47     ControllerNumAxes: array[0..5] of Integer;
    60     ControllerNumAxes: array[0..5] of Integer;
    48     //ControllerNumBalls: array[0..5] of Integer;
    61     //ControllerNumBalls: array[0..5] of Integer;
    49 	ControllerNumHats: array[0..5] of Integer;
    62 	ControllerNumHats: array[0..5] of Integer;
    54 	ControllerButtons: array[0..5] of array[0..19] of Byte;
    67 	ControllerButtons: array[0..5] of array[0..19] of Byte;
    55 
    68 
    56 implementation
    69 implementation
    57 uses SDLh, uTeams, uConsole, uMisc, uStore;
    70 uses SDLh, uTeams, uConsole, uMisc, uStore;
    58 const KeyNumber = 1024;
    71 const KeyNumber = 1024;
    59 type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
       
    60 
    72 
    61 var tkbd, tkbdn: TKeyboardState;
    73 var tkbd, tkbdn: TKeyboardState;
    62     KeyNames: array [0..cKeyMaxIndex] of string[15];
    74     KeyNames: array [0..cKeyMaxIndex] of string[15];
    63     DefaultBinds, CurrentBinds: TBinds;
    75     DefaultBinds, CurrentBinds: TBinds;
    64 
    76 
   109 // mouse wheels (see event loop in project file)
   121 // mouse wheels (see event loop in project file)
   110 tkbdn[4]:= ord(wheelDown);
   122 tkbdn[4]:= ord(wheelDown);
   111 tkbdn[5]:= ord(wheelUp);
   123 tkbdn[5]:= ord(wheelUp);
   112 wheelUp:= false;
   124 wheelUp:= false;
   113 wheelDown:= false;
   125 wheelDown:= false;
       
   126 {$IFDEF IPHONEOS}
       
   127 tkbdn[1]:= ord(leftClick);
       
   128 tkbdn[2]:= ord(middleClick);
       
   129 tkbdn[3]:= ord(rightClick);
       
   130 leftClick:= false;
       
   131 middleClick:= false;
       
   132 rightClick:= false;
       
   133 
       
   134 {*
       
   135 //sdl1.3 for these keys is messed up
       
   136 tkbdn[273]:= ord(upKey);
       
   137 tkbdn[274]:= ord(downKey);
       
   138 tkbdn[275]:= ord(rightKey);
       
   139 tkbdn[276]:= ord(leftKey);
       
   140 
       
   141 tkbdn[32]:= ord(spaceKey);
       
   142 tkbdn[13]:= ord(enterKey);
       
   143 
       
   144 upKey:= false;
       
   145 downKey:= false;
       
   146 rightKey:= false;
       
   147 leftKey:= false;
       
   148 
       
   149 spaceKey:= false;
       
   150 enterKey:= false;
       
   151 *}
       
   152 {$ENDIF}
   114 
   153 
   115 // Controller(s)
   154 // Controller(s)
   116 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   155 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   117 for j:= 0 to Pred(ControllerNumControllers) do
   156 for j:= 0 to Pred(ControllerNumControllers) do
   118 	begin
   157 	begin
   160     pkbd: PByteArray;
   199     pkbd: PByteArray;
   161 begin
   200 begin
   162 
   201 
   163 {$IFDEF SDL13}
   202 {$IFDEF SDL13}
   164 pkbd:= SDL_GetKeyboardState(@j);
   203 pkbd:= SDL_GetKeyboardState(@j);
   165 k    := SDL_GetMouseState(0, nil, nil);
   204 k:= SDL_GetMouseState(0, nil, nil);
   166 {$ELSE}
   205 {$ELSE}
   167 pkbd:= SDL_GetKeyState(@j);
   206 pkbd:= SDL_GetKeyState(@j);
   168 k    := SDL_GetMouseState(nil, nil);
   207 k:= SDL_GetMouseState(nil, nil);
   169 {$ENDIF}
   208 {$ENDIF}
   170 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
   209 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
   171 
   210 
   172 for i:= 1 to pred(j) do
   211 for i:= 1 to pred(j) do
   173 	tkbdn[i]:= pkbd^[i];
   212 	tkbdn[i]:= pkbd^[i];
   185 // mouse wheels (see event loop in project file)
   224 // mouse wheels (see event loop in project file)
   186 tkbdn[4]:= ord(wheelDown);
   225 tkbdn[4]:= ord(wheelDown);
   187 tkbdn[5]:= ord(wheelUp);
   226 tkbdn[5]:= ord(wheelUp);
   188 wheelUp:= false;
   227 wheelUp:= false;
   189 wheelDown:= false;
   228 wheelDown:= false;
       
   229 {$IFDEF IPHONEOS}
       
   230 tkbdn[1]:= ord(leftClick);
       
   231 tkbdn[2]:= ord(middleClick);
       
   232 tkbdn[3]:= ord(rightClick);
       
   233 leftClick:= false;
       
   234 middleClick:= false;
       
   235 rightClick:= false;
       
   236 
       
   237 {*
       
   238 tkbdn[273]:= ord(upKey);
       
   239 tkbdn[274]:= ord(downKey);
       
   240 tkbdn[275]:= ord(rightKey);
       
   241 tkbdn[276]:= ord(leftKey);
       
   242 
       
   243 tkbdn[32]:= ord(spaceKey);
       
   244 tkbdn[13]:= ord(enterKey);
       
   245 
       
   246 upKey:= false;
       
   247 downKey:= false;
       
   248 rightKey:= false;
       
   249 leftKey:= false;
       
   250 
       
   251 spaceKey:= false;
       
   252 enterKey:= false;
       
   253 *}
       
   254 {$ENDIF}
   190 
   255 
   191 // Controller(s)
   256 // Controller(s)
   192 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   257 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   193 for j:= 0 to Pred(ControllerNumControllers) do
   258 for j:= 0 to Pred(ControllerNumControllers) do
   194 	begin
   259 	begin
   303 end;
   368 end;
   304 
   369 
   305 procedure FreezeEnterKey;
   370 procedure FreezeEnterKey;
   306 begin
   371 begin
   307 tkbd[13]:= 1;
   372 tkbd[13]:= 1;
   308 tkbd[271]:= 1
   373 tkbd[271]:= 1;
   309 end;
   374 end;
   310 
   375 
   311 var Controller: array [0..5] of PSDLJoystick;
   376 var Controller: array [0..5] of PSDLJoystick;
   312 	
   377 	
   313 procedure ControllerInit;
   378 procedure ControllerInit;