- Added support for keyboards on android
authorXeli
Sat, 21 Apr 2012 17:59:14 +0200
changeset 6900 26873e68034f
parent 6899 c3d44a836086
child 6901 c021699c33dc
- Added support for keyboards on android - tiny patch for android/sdl tracks backspace correctly now - Added SDL_SCANCODE_X constants in uKeys - First attempt at making the touch interface and keys input work side by side
hedgewars/SDLh.pas
hedgewars/uKeys.pas
project_files/Android-build/SDL-android-project/jni/SDL/src/video/android/SDL_androidkeyboard.c
--- a/hedgewars/SDLh.pas	Sat Apr 21 17:55:45 2012 +0200
+++ b/hedgewars/SDLh.pas	Sat Apr 21 17:59:14 2012 +0200
@@ -291,6 +291,272 @@
     IMG_INIT_PNG = $00000002;
     IMG_INIT_TIF = $00000004;
 
+    {* SDL SCANCODES see SDL/include/SDL_scancode.h *}
+    SDL_SCANCODE_UNKNOWN = 0;
+
+    SDL_SCANCODE_MOUSEL = 1;
+    SDL_SCANCODE_MOUSEM = 2;
+    SDL_SCANCODE_MOUSER = 3;
+
+    SDL_SCANCODE_A = 4;
+    SDL_SCANCODE_B = 5;
+    SDL_SCANCODE_C = 6;
+    SDL_SCANCODE_D = 7;
+    SDL_SCANCODE_E = 8;
+    SDL_SCANCODE_F = 9;
+    SDL_SCANCODE_G = 10;
+    SDL_SCANCODE_H = 11;
+    SDL_SCANCODE_I = 12;
+    SDL_SCANCODE_J = 13;
+    SDL_SCANCODE_K = 14;
+    SDL_SCANCODE_L = 15;
+    SDL_SCANCODE_M = 16;
+    SDL_SCANCODE_N = 17;
+    SDL_SCANCODE_O = 18;
+    SDL_SCANCODE_P = 19;
+    SDL_SCANCODE_Q = 20;
+    SDL_SCANCODE_R = 21;
+    SDL_SCANCODE_S = 22;
+    SDL_SCANCODE_T = 23;
+    SDL_SCANCODE_U = 24;
+    SDL_SCANCODE_V = 25;
+    SDL_SCANCODE_W = 26;
+    SDL_SCANCODE_X = 27;
+    SDL_SCANCODE_Y = 28;
+    SDL_SCANCODE_Z = 29;
+
+    SDL_SCANCODE_1 = 30;
+    SDL_SCANCODE_2 = 31;
+    SDL_SCANCODE_3 = 32;
+    SDL_SCANCODE_4 = 33;
+    SDL_SCANCODE_5 = 34;
+    SDL_SCANCODE_6 = 35;
+    SDL_SCANCODE_7 = 36;
+    SDL_SCANCODE_8 = 37;
+    SDL_SCANCODE_9 = 38;
+    SDL_SCANCODE_0 = 39;
+
+    SDL_SCANCODE_RETURN = 40;
+    SDL_SCANCODE_ESCAPE = 41;
+    SDL_SCANCODE_BACKSPACE = 42;
+    SDL_SCANCODE_TAB = 43;
+    SDL_SCANCODE_SPACE = 44;
+
+    SDL_SCANCODE_MINUS = 45;
+    SDL_SCANCODE_EQUALS = 46;
+    SDL_SCANCODE_LEFTBRACKET = 47;
+    SDL_SCANCODE_RIGHTBRACKET = 48;
+    SDL_SCANCODE_BACKSLASH = 49; 
+    SDL_SCANCODE_NONUSHASH = 50;
+    SDL_SCANCODE_SEMICOLON = 51;
+    SDL_SCANCODE_APOSTROPHE = 52;
+    SDL_SCANCODE_GRAVE = 53; 
+    SDL_SCANCODE_COMMA = 54;
+    SDL_SCANCODE_PERIOD = 55;
+    SDL_SCANCODE_SLASH = 56;
+
+    SDL_SCANCODE_CAPSLOCK = 57;
+
+    SDL_SCANCODE_F1 = 58;
+    SDL_SCANCODE_F2 = 59;
+    SDL_SCANCODE_F3 = 60;
+    SDL_SCANCODE_F4 = 61;
+    SDL_SCANCODE_F5 = 62;
+    SDL_SCANCODE_F6 = 63;
+    SDL_SCANCODE_F7 = 64;
+    SDL_SCANCODE_F8 = 65;
+    SDL_SCANCODE_F9 = 66;
+    SDL_SCANCODE_F10 = 67;
+    SDL_SCANCODE_F11 = 68;
+    SDL_SCANCODE_F12 = 69;
+
+    SDL_SCANCODE_PRINTSCREEN = 70;
+    SDL_SCANCODE_SCROLLLOCK = 71;
+    SDL_SCANCODE_PAUSE = 72;
+    SDL_SCANCODE_INSERT = 73; 
+    SDL_SCANCODE_HOME = 74;
+    SDL_SCANCODE_PAGEUP = 75;
+    SDL_SCANCODE_DELETE = 76;
+    SDL_SCANCODE_END = 77;
+    SDL_SCANCODE_PAGEDOWN = 78;
+    SDL_SCANCODE_RIGHT = 79;
+    SDL_SCANCODE_LEFT = 80;
+    SDL_SCANCODE_DOWN = 81;
+    SDL_SCANCODE_UP = 82;
+
+    SDL_SCANCODE_NUMLOCKCLEAR = 83; 
+    SDL_SCANCODE_KP_DIVIDE = 84;
+    SDL_SCANCODE_KP_MULTIPLY = 85;
+    SDL_SCANCODE_KP_MINUS = 86;
+    SDL_SCANCODE_KP_PLUS = 87;
+    SDL_SCANCODE_KP_ENTER = 88;
+    SDL_SCANCODE_KP_1 = 89;
+    SDL_SCANCODE_KP_2 = 90;
+    SDL_SCANCODE_KP_3 = 91;
+    SDL_SCANCODE_KP_4 = 92;
+    SDL_SCANCODE_KP_5 = 93;
+    SDL_SCANCODE_KP_6 = 94;
+    SDL_SCANCODE_KP_7 = 95;
+    SDL_SCANCODE_KP_8 = 96;
+    SDL_SCANCODE_KP_9 = 97;
+    SDL_SCANCODE_KP_0 = 98;
+    SDL_SCANCODE_KP_PERIOD = 99;
+
+    SDL_SCANCODE_NONUSBACKSLASH = 100;
+    SDL_SCANCODE_APPLICATION = 101; 
+    SDL_SCANCODE_POWER = 102; 
+    SDL_SCANCODE_KP_EQUALS = 103;
+    SDL_SCANCODE_F13 = 104;
+    SDL_SCANCODE_F14 = 105;
+    SDL_SCANCODE_F15 = 106;
+    SDL_SCANCODE_F16 = 107;
+    SDL_SCANCODE_F17 = 108;
+    SDL_SCANCODE_F18 = 109;
+    SDL_SCANCODE_F19 = 110;
+    SDL_SCANCODE_F20 = 111;
+    SDL_SCANCODE_F21 = 112;
+    SDL_SCANCODE_F22 = 113;
+    SDL_SCANCODE_F23 = 114;
+    SDL_SCANCODE_F24 = 115;
+    SDL_SCANCODE_EXECUTE = 116;
+    SDL_SCANCODE_HELP = 117;
+    SDL_SCANCODE_MENU = 118;
+    SDL_SCANCODE_SELECT = 119;
+    SDL_SCANCODE_STOP = 120;
+    SDL_SCANCODE_AGAIN = 121; 
+    SDL_SCANCODE_UNDO = 122;
+    SDL_SCANCODE_CUT = 123;
+    SDL_SCANCODE_COPY = 124;
+    SDL_SCANCODE_PASTE = 125;
+    SDL_SCANCODE_FIND = 126;
+    SDL_SCANCODE_MUTE = 127;
+    SDL_SCANCODE_VOLUMEUP = 128;
+    SDL_SCANCODE_VOLUMEDOWN = 129;
+    SDL_SCANCODE_KP_COMMA = 133;
+    SDL_SCANCODE_KP_EQUALSAS400 = 134;
+
+    SDL_SCANCODE_INTERNATIONAL1 = 135; 
+    SDL_SCANCODE_INTERNATIONAL2 = 136;
+    SDL_SCANCODE_INTERNATIONAL3 = 137; 
+    SDL_SCANCODE_INTERNATIONAL4 = 138;
+    SDL_SCANCODE_INTERNATIONAL5 = 139;
+    SDL_SCANCODE_INTERNATIONAL6 = 140;
+    SDL_SCANCODE_INTERNATIONAL7 = 141;
+    SDL_SCANCODE_INTERNATIONAL8 = 142;
+    SDL_SCANCODE_INTERNATIONAL9 = 143;
+    SDL_SCANCODE_LANG1 = 144;
+    SDL_SCANCODE_LANG2 = 145;
+    SDL_SCANCODE_LANG3 = 146;
+    SDL_SCANCODE_LANG4 = 147;
+    SDL_SCANCODE_LANG5 = 148;
+    SDL_SCANCODE_LANG6 = 149;
+    SDL_SCANCODE_LANG7 = 150;
+    SDL_SCANCODE_LANG8 = 151;
+    SDL_SCANCODE_LANG9 = 152;
+
+    SDL_SCANCODE_ALTERASE = 153;
+    SDL_SCANCODE_SYSREQ = 154;
+    SDL_SCANCODE_CANCEL = 155;
+    SDL_SCANCODE_CLEAR = 156;
+    SDL_SCANCODE_PRIOR = 157;
+    SDL_SCANCODE_RETURN2 = 158;
+    SDL_SCANCODE_SEPARATOR = 159;
+    SDL_SCANCODE_OUT = 160;
+    SDL_SCANCODE_OPER = 161;
+    SDL_SCANCODE_CLEARAGAIN = 162;
+    SDL_SCANCODE_CRSEL = 163;
+    SDL_SCANCODE_EXSEL = 164;
+
+    SDL_SCANCODE_KP_00 = 176;
+    SDL_SCANCODE_KP_000 = 177;
+    SDL_SCANCODE_THOUSANDSSEPARATOR = 178;
+    SDL_SCANCODE_DECIMALSEPARATOR = 179;
+    SDL_SCANCODE_CURRENCYUNIT = 180;
+    SDL_SCANCODE_CURRENCYSUBUNIT = 181;
+    SDL_SCANCODE_KP_LEFTPAREN = 182;
+    SDL_SCANCODE_KP_RIGHTPAREN = 183;
+    SDL_SCANCODE_KP_LEFTBRACE = 184;
+    SDL_SCANCODE_KP_RIGHTBRACE = 185;
+    SDL_SCANCODE_KP_TAB = 186;
+    SDL_SCANCODE_KP_BACKSPACE = 187;
+    SDL_SCANCODE_KP_A = 188;
+    SDL_SCANCODE_KP_B = 189;
+    SDL_SCANCODE_KP_C = 190;
+    SDL_SCANCODE_KP_D = 191;
+    SDL_SCANCODE_KP_E = 192;
+    SDL_SCANCODE_KP_F = 193;
+    SDL_SCANCODE_KP_XOR = 194;
+    SDL_SCANCODE_KP_POWER = 195;
+    SDL_SCANCODE_KP_PERCENT = 196;
+    SDL_SCANCODE_KP_LESS = 197;
+    SDL_SCANCODE_KP_GREATER = 198;
+    SDL_SCANCODE_KP_AMPERSAND = 199;
+    SDL_SCANCODE_KP_DBLAMPERSAND = 200;
+    SDL_SCANCODE_KP_VERTICALBAR = 201;
+    SDL_SCANCODE_KP_DBLVERTICALBAR = 202;
+    SDL_SCANCODE_KP_COLON = 203;
+    SDL_SCANCODE_KP_HASH = 204;
+    SDL_SCANCODE_KP_SPACE = 205;
+    SDL_SCANCODE_KP_AT = 206;
+    SDL_SCANCODE_KP_EXCLAM = 207;
+    SDL_SCANCODE_KP_MEMSTORE = 208;
+    SDL_SCANCODE_KP_MEMRECALL = 209;
+    SDL_SCANCODE_KP_MEMCLEAR = 210;
+    SDL_SCANCODE_KP_MEMADD = 211;
+    SDL_SCANCODE_KP_MEMSUBTRACT = 212;
+    SDL_SCANCODE_KP_MEMMULTIPLY = 213;
+    SDL_SCANCODE_KP_MEMDIVIDE = 214;
+    SDL_SCANCODE_KP_PLUSMINUS = 215;
+    SDL_SCANCODE_KP_CLEAR = 216;
+    SDL_SCANCODE_KP_CLEARENTRY = 217;
+    SDL_SCANCODE_KP_BINARY = 218;
+    SDL_SCANCODE_KP_OCTAL = 219;
+    SDL_SCANCODE_KP_DECIMAL = 220;
+    SDL_SCANCODE_KP_HEXADECIMAL = 221;
+
+    SDL_SCANCODE_LCTRL = 224;
+    SDL_SCANCODE_LSHIFT = 225;
+    SDL_SCANCODE_LALT = 226;
+    SDL_SCANCODE_LGUI = 227;
+    SDL_SCANCODE_RCTRL = 228;
+    SDL_SCANCODE_RSHIFT = 229;
+    SDL_SCANCODE_RALT = 230;
+    SDL_SCANCODE_RGUI = 231;
+
+    SDL_SCANCODE_MODE = 257;
+
+    SDL_SCANCODE_AUDIONEXT = 258;
+    SDL_SCANCODE_AUDIOPREV = 259;
+    SDL_SCANCODE_AUDIOSTOP = 260;
+    SDL_SCANCODE_AUDIOPLAY = 261;
+    SDL_SCANCODE_AUDIOMUTE = 262;
+    SDL_SCANCODE_MEDIASELECT = 263;
+    SDL_SCANCODE_WWW = 264;
+    SDL_SCANCODE_MAIL = 265;
+    SDL_SCANCODE_CALCULATOR = 266;
+    SDL_SCANCODE_COMPUTER = 267;
+    SDL_SCANCODE_AC_SEARCH = 268;
+    SDL_SCANCODE_AC_HOME = 269;
+    SDL_SCANCODE_AC_BACK = 270;
+    SDL_SCANCODE_AC_FORWARD = 271;
+    SDL_SCANCODE_AC_STOP = 272;
+    SDL_SCANCODE_AC_REFRESH = 273;
+    SDL_SCANCODE_AC_BOOKMARKS = 274;
+    
+    SDL_SCANCODE_BRIGHTNESSDOWN = 275;
+    SDL_SCANCODE_BRIGHTNESSUP = 276;
+    SDL_SCANCODE_DISPLAYSWITCH = 277;
+    SDL_SCANCODE_KBDILLUMTOGGLE = 278;
+    SDL_SCANCODE_KBDILLUMDOWN = 279;
+    SDL_SCANCODE_KBDILLUMUP = 280;
+    SDL_SCANCODE_EJECT = 281;
+    SDL_SCANCODE_SLEEP = 282;
+   
+    SDL_SCANCODE_WHEELUP = 300;
+    SDL_SCANCODE_WHEELDOWN = 301;
+    SDL_SCANCODE_CONTROLLER = 310;
+    SDL_NUM_SCANCODES = 512;
+
     {* SDL_EventMask type definition *}
 
 /////////////////////////////////////////////////////////////////
@@ -916,6 +1182,7 @@
 
 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
 function  SDL_GetKeyName(key: LongWord): PChar; cdecl; external SDLLibName;
+function  SDL_GetScancodeName(key: LongWord): PChar; cdecl; external SDLLibName;
 
 procedure SDL_PumpEvents; cdecl; external SDLLibName;
 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
--- a/hedgewars/uKeys.pas	Sat Apr 21 17:55:45 2012 +0200
+++ b/hedgewars/uKeys.pas	Sat Apr 21 17:59:14 2012 +0200
@@ -41,7 +41,7 @@
 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
 
 {$IFDEF MOBILE}
-procedure setiPhoneBinds;
+procedure setTouchWidgetStates;
 {$ENDIF}
 
 implementation
@@ -63,7 +63,7 @@
 var  i, j, k: LongInt;
      s: shortstring;
      Trusted: boolean;
-{$IFNDEF MOBILE}pkbd: PByteArray;{$ENDIF}
+     pkbd: PByteArray;
 begin
 hideAmmoMenu:= false;
 Trusted:= (CurrentTeam <> nil)
@@ -74,37 +74,34 @@
 // TODO: Scale on screen dimensions and/or axis value (game controller)?
 movecursor(5 * CursorMovementX, 5 * CursorMovementY);
 
-k:= SDL_GetMouseState(nil, nil);
+pkbd:= SDL_GetKeyState(@j);
+for i:= 1 to pred(j) do 
+    tkbdn[i]:= pkbd^[i];
 
-{$IFDEF MOBILE}
-SDL_GetKeyState(@j);
-{$ELSE}
-pkbd:= SDL_GetKeyState(@j);
-for i:= 6 to pred(j) do // first 6 will be overwritten
-    tkbdn[i]:= pkbd^[i];
-{$ENDIF}
-
+k:= SDL_GetMouseState(nil, nil);
 // mouse buttons
 {$IFDEF DARWIN}
-tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
-tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
+tkbdn[SDL_SCANCODE_MOUSEL]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
+tkbdni[SDL_SCANCODE_MOUSER]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
 {$ELSE}
-tkbdn[1]:= (k and 1);
-tkbdn[3]:= ((k shr 2) and 1);
+tkbdn[SDL_SCANCODE_MOUSEL]:= (k and 1);
+tkbdn[SDL_SCANCODE_MOUSER]:= ((k shr 2) and 1);
 {$ENDIF}
-tkbdn[2]:= ((k shr 1) and 1);
+tkbdn[SDL_SCANCODE_MOUSEM]:= ((k shr 1) and 1);
 
 // mouse wheels
-tkbdn[4]:= ord(wheelDown);
-tkbdn[5]:= ord(wheelUp);
+tkbdn[SDL_SCANCODE_WHEELDOWN]:= ord(wheelDown);
+tkbdn[SDL_SCANCODE_WHEELUP]:= ord(wheelUp);
 wheelUp:= false;
 wheelDown:= false;
 
 {$IFDEF MOBILE}
-setiPhoneBinds();
-{$ELSE}
+setTouchWidgetStates();
+{$ENDIF}
+
+{$IFNDEF MOBILE}
 // Controller(s)
-k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
+k:= SDL_SCANCODE_CONTROLLER; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
 for j:= 0 to Pred(ControllerNumControllers) do
     begin
     for i:= 0 to Pred(ControllerNumAxes[j]) do
@@ -137,12 +134,12 @@
 
 // ctrl/cmd + q to close engine and frontend
 {$IFDEF DARWIN}
-    if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
+    if ((tkbdn[SDL_SCANCODE_LGUI] = 1) or (tkbdn[SDL_SCANCODE_RGUI] = 1)) then
 {$ELSE}
-    if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
+    if ((tkbdn[SDL_SCANCODE_LCTRL] = 1) or (tkbdn[SDL_SCANCODE_RCTRL] = 1)) then
 {$ENDIF}
     begin
-        if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true)
+        if tkbdn[SDL_SCANCODE_Q] = 1 then ParseCommand ('halt', true)
     end;
 
 // now process strokes
@@ -170,43 +167,41 @@
 
 procedure ResetKbd;
 var j, k, t: LongInt;
-{$IFNDEF MOBILE}
     i: LongInt;
     pkbd: PByteArray;
-{$ENDIF}
 begin
 
 k:= SDL_GetMouseState(nil, nil);
-{$IFNDEF MOBILE}pkbd:={$ENDIF}SDL_GetKeyState(@j);
+pkbd:=SDL_GetKeyState(@j);
 
 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true);
 
-{$IFNDEF MOBILE}
 for i:= 1 to pred(j) do
     tkbdn[i]:= pkbd^[i];
-{$ENDIF}
 
 // mouse buttons
 {$IFDEF DARWIN}
-tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
-tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
+tkbdn[SDL_SCANCODE_MOUSEL]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
+tkbdn[SDL_SCANCODE_MOUSER]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
 {$ELSE}
-tkbdn[1]:= (k and 1);
-tkbdn[3]:= ((k shr 2) and 1);
+tkbdn[SDL_SCANCODE_MOUSEL]:= (k and 1);
+tkbdn[SDL_SCANCODE_MOUSER]:= ((k shr 2) and 1);
 {$ENDIF}
-tkbdn[2]:= ((k shr 1) and 1);
+tkbdn[SDL_SCANCODE_MOUSEM]:= ((k shr 1) and 1);
 
 // mouse wheels
-tkbdn[4]:= ord(wheelDown);
-tkbdn[5]:= ord(wheelUp);
+tkbdn[SDL_SCANCODE_WHEELDOWN]:= ord(wheelDown);
+tkbdn[SDL_SCANCODE_WHEELUP]:= ord(wheelUp);
 wheelUp:= false;
 wheelDown:= false;
 
 {$IFDEF MOBILE}
-setiPhoneBinds();
-{$ELSE}
+setTouchWidgetStates();
+{$ENDIF}
+
+{$IFNDEF MOBILE}
 // Controller(s)
-k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
+k:= SDL_SCANCODE_CONTROLLER; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
 for j:= 0 to Pred(ControllerNumControllers) do
     begin
     for i:= 0 to Pred(ControllerNumAxes[j]) do
@@ -246,16 +241,10 @@
 var i, j, k, t: LongInt;
     s: string[15];
 begin
-KeyNames[1]:= 'mousel';
-KeyNames[2]:= 'mousem';
-KeyNames[3]:= 'mouser';
-KeyNames[4]:= 'wheelup';
-KeyNames[5]:= 'wheeldown';
-
-for i:= 6 to cKeyMaxIndex do
+for i:= 0 to cKeyMaxIndex do
     begin
     s:= shortstring(sdl_getkeyname(i));
-    //writeln(stdout,IntToStr(i) + ': ' + s);
+    //WriteToConsole(IntToStr(i) + ': ' + s);
     if s = 'unknown key' then KeyNames[i]:= ''
     else 
         begin
@@ -266,11 +255,14 @@
         end;
     end;
 
+KeyNames[SDL_SCANCODE_MOUSEL]:= 'mousel';
+KeyNames[SDL_SCANCODE_MOUSEM]:= 'mousem';
+KeyNames[SDL_SCANCODE_MOUSER]:= 'mouser';
+KeyNames[SDL_SCANCODE_WHEELUP]:= 'wheelup';
+KeyNames[SDL_SCANCODE_WHEELDOWN]:= 'wheeldown';
 //for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]);
 
-// get the size of keyboard array
-SDL_GetKeyState(@k);
-
+k:= SDL_SCANCODE_CONTROLLER;
 // Controller(s)
 for j:= 0 to Pred(ControllerNumControllers) do
     begin
@@ -295,54 +287,59 @@
         end;
     end;
 
-DefaultBinds[ 27]:= 'quit';
-DefaultBinds[ 96]:= 'history';
+DefaultBinds[SDL_SCANCODE_ESCAPE]:= 'quit';
+DefaultBinds[SDL_SCANCODE_GRAVE]:= 'history';
 DefaultBinds[127]:= 'rotmask';
 
 //numpad
 //DefaultBinds[265]:= '+volup';
 //DefaultBinds[256]:= '+voldown';
 
-DefaultBinds[KeyNameToCode('0')]:= '+volup';
-DefaultBinds[KeyNameToCode('9')]:= '+voldown';
-DefaultBinds[KeyNameToCode('c')]:= 'capture';
-DefaultBinds[KeyNameToCode('h')]:= 'findhh';
-DefaultBinds[KeyNameToCode('p')]:= 'pause';
-DefaultBinds[KeyNameToCode('s')]:= '+speedup';
-DefaultBinds[KeyNameToCode('t')]:= 'chat';
-DefaultBinds[KeyNameToCode('y')]:= 'confirm';
+DefaultBinds[SDL_SCANCODE_0]:= '+volup';
+DefaultBinds[SDL_SCANCODE_9]:= '+voldown';
+DefaultBinds[SDL_SCANCODE_C]:= 'capture';
+DefaultBinds[SDL_SCANCODE_H]:= 'findhh';
+DefaultBinds[SDL_SCANCODE_P]:= 'pause';
+DefaultBinds[SDL_SCANCODE_S]:= '+speedup';
+DefaultBinds[SDL_SCANCODE_T]:= 'chat';
+DefaultBinds[SDL_SCANCODE_Y]:= 'confirm';
 
-DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset';
-DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout';
-DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin';
+DefaultBinds[SDL_SCANCODE_MOUSEM]:= 'zoomreset';
+DefaultBinds[SDL_SCANCODE_WHEELUP]:= 'zoomout';
+DefaultBinds[SDL_SCANCODE_WHEELDOWN]:= 'zoomin';
 
-DefaultBinds[KeyNameToCode('f12')]:= 'fullscr';
+DefaultBinds[SDL_SCANCODE_F12]:= 'fullscr';
 
 
-DefaultBinds[ 1]:= '/put';
-DefaultBinds[ 3]:= 'ammomenu';
-DefaultBinds[ 8]:= 'hjump';
-DefaultBinds[ 9]:= 'switch';
-DefaultBinds[13]:= 'ljump';
-DefaultBinds[32]:= '+attack';
-{$IFDEF MOBILE}
-DefaultBinds[23]:= '+up';
-DefaultBinds[24]:= '+down';
-DefaultBinds[25]:= '+left';
-DefaultBinds[26]:= '+right';
-DefaultBinds[27]:= '+precise';
-DefaultBinds[44]:= 'chat';
-DefaultBinds[55]:= 'pause';
-{$ELSE}
-DefaultBinds[KeyNameToCode('up')]:= '+up';
-DefaultBinds[KeyNameToCode('down')]:= '+down';
-DefaultBinds[KeyNameToCode('left')]:= '+left';
-DefaultBinds[KeyNameToCode('right')]:= '+right';
-DefaultBinds[KeyNameToCode('left_shift')]:= '+precise';
-{$ENDIF}
+DefaultBinds[SDL_SCANCODE_MOUSEL]:= '/put';
+DefaultBinds[SDL_SCANCODE_MOUSER]:= 'ammomenu';
+DefaultBinds[SDL_SCANCODE_BACKSPACE]:= 'hjump';
+DefaultBinds[SDL_SCANCODE_TAB]:= 'switch';
+DefaultBinds[SDL_SCANCODE_RETURN]:= 'ljump';
+DefaultBinds[SDL_SCANCODE_SPACE]:= '+attack';
+
+DefaultBinds[SDL_SCANCODE_UP]:= '+up';
+DefaultBinds[SDL_SCANCODE_DOWN]:= '+down';
+DefaultBinds[SDL_SCANCODE_LEFT]:= '+left';
+DefaultBinds[SDL_SCANCODE_RIGHT]:= '+right';
+DefaultBinds[SDL_SCANCODE_LSHIFT]:= '+precise';
 
-for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
-for i:= 1 to 5  do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i);
+DefaultBinds[SDL_SCANCODE_F1]:= 'slot 1';
+DefaultBinds[SDL_SCANCODE_F2]:= 'slot 2';
+DefaultBinds[SDL_SCANCODE_F3]:= 'slot 3';
+DefaultBinds[SDL_SCANCODE_F4]:= 'slot 4';
+DefaultBinds[SDL_SCANCODE_F5]:= 'slot 5';
+DefaultBinds[SDL_SCANCODE_F6]:= 'slot 6';
+DefaultBinds[SDL_SCANCODE_F7]:= 'slot 7';
+DefaultBinds[SDL_SCANCODE_F8]:= 'slot 8';
+DefaultBinds[SDL_SCANCODE_F9]:= 'slot 9';
+DefaultBinds[SDL_SCANCODE_F10]:= 'slot 10';
+
+DefaultBinds[SDL_SCANCODE_1]:= 'timer 1';
+DefaultBinds[SDL_SCANCODE_2]:= 'timer 2';
+DefaultBinds[SDL_SCANCODE_3]:= 'timer 3';
+DefaultBinds[SDL_SCANCODE_4]:= 'timer 4';
+DefaultBinds[SDL_SCANCODE_5]:= 'timer 5';
 
 SetDefaultBinds();
 end;
@@ -363,25 +360,25 @@
 end;
 
 {$IFDEF MOBILE}
-procedure setiPhoneBinds;
+procedure setTouchWidgetStates;
 begin
-    tkbdn[ 1]:= ord(leftClick);
-    tkbdn[ 2]:= ord(middleClick);
-    tkbdn[ 3]:= ord(rightClick);
+    tkbdn[SDL_SCANCODE_MOUSEL]:= tkbdn[SDL_SCANCODE_MOUSEL] or ord(leftClick);
+    tkbdn[SDL_SCANCODE_MOUSEM]:= tkbdn[SDL_SCANCODE_MOUSEM] or ord(middleClick);
+    tkbdn[SDL_SCANCODE_MOUSER]:= tkbdn[SDL_SCANCODE_MOUSER] or ord(rightClick);
 
-    tkbdn[23]:= ord(upKey);
-    tkbdn[24]:= ord(downKey);
-    tkbdn[25]:= ord(leftKey);
-    tkbdn[26]:= ord(rightKey);
-    tkbdn[27]:= ord(preciseKey);
+    tkbdn[SDL_SCANCODE_UP]    := tkbdn[SDL_SCANCODE_UP] or ord(upKey);
+    tkbdn[SDL_SCANCODE_DOWN]  := tkbdn[SDL_SCANCODE_DOWN] or ord(downKey);
+    tkbdn[SDL_SCANCODE_LEFT]  := tkbdn[SDL_SCANCODE_LEFT] or ord(leftKey);
+    tkbdn[SDL_SCANCODE_RIGHT] := tkbdn[SDL_SCANCODE_RIGHT] or ord(rightKey);
+    tkbdn[SDL_SCANCODE_LSHIFT]:= tkbdn[SDL_SCANCODE_LSHIFT] or ord(preciseKey);
 
-    tkbdn[ 8]:= ord(backspaceKey);
-    tkbdn[ 9]:= ord(tabKey);
-    tkbdn[13]:= ord(enterKey);
-    tkbdn[32]:= ord(spaceKey);
+    tkbdn[SDL_SCANCODE_BACKSPACE]:= tkbdn[SDL_SCANCODE_BACKSPACE] or ord(backspaceKey);
+    tkbdn[SDL_SCANCODE_TAB]:= tkbdn[SDL_SCANCODE_TAB] or ord(tabKey);
+    tkbdn[SDL_SCANCODE_RETURN]:= ord(enterKey);
+    tkbdn[SDL_SCANCODE_SPACE]:= ord(spaceKey);
 
-    tkbdn[44]:= ord(chatAction);
-    tkbdn[55]:= ord(pauseAction);
+    tkbdn[SDL_SCANCODE_T]:= tkbdn[SDL_SCANCODE_T] or ord(chatAction);
+    tkbdn[SDL_SCANCODE_PAUSE]:= ord(pauseAction);
 
     // set to false the keys that only need one stoke
     leftClick:= false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/video/android/SDL_androidkeyboard.c	Sat Apr 21 17:59:14 2012 +0200
@@ -0,0 +1,185 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include <android/log.h>
+
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_androidkeyboard.h"
+#include "SDL_keycode.h"
+
+
+void Android_InitKeyboard()
+{
+    SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+    /* Add default scancode to key mapping */
+    SDL_GetDefaultKeymap(keymap);
+    SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+}
+
+static SDL_Scancode Android_Keycodes[] = {
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_LEFT */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */
+    SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
+    SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALL */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENDCALL */
+    SDL_SCANCODE_0, /* AKEYCODE_0 */
+    SDL_SCANCODE_1, /* AKEYCODE_1 */
+    SDL_SCANCODE_2, /* AKEYCODE_2 */
+    SDL_SCANCODE_3, /* AKEYCODE_3 */
+    SDL_SCANCODE_4, /* AKEYCODE_4 */
+    SDL_SCANCODE_5, /* AKEYCODE_5 */
+    SDL_SCANCODE_6, /* AKEYCODE_6 */
+    SDL_SCANCODE_7, /* AKEYCODE_7 */
+    SDL_SCANCODE_8, /* AKEYCODE_8 */
+    SDL_SCANCODE_9, /* AKEYCODE_9 */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
+    SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
+    SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
+    SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
+    SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
+    SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
+    SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
+    SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
+    SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
+    SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
+    SDL_SCANCODE_A, /* AKEYCODE_A */
+    SDL_SCANCODE_B, /* AKEYCODE_B */
+    SDL_SCANCODE_C, /* AKEYCODE_C */
+    SDL_SCANCODE_D, /* AKEYCODE_D */
+    SDL_SCANCODE_E, /* AKEYCODE_E */
+    SDL_SCANCODE_F, /* AKEYCODE_F */
+    SDL_SCANCODE_G, /* AKEYCODE_G */
+    SDL_SCANCODE_H, /* AKEYCODE_H */
+    SDL_SCANCODE_I, /* AKEYCODE_I */
+    SDL_SCANCODE_J, /* AKEYCODE_J */
+    SDL_SCANCODE_K, /* AKEYCODE_K */
+    SDL_SCANCODE_L, /* AKEYCODE_L */
+    SDL_SCANCODE_M, /* AKEYCODE_M */
+    SDL_SCANCODE_N, /* AKEYCODE_N */
+    SDL_SCANCODE_O, /* AKEYCODE_O */
+    SDL_SCANCODE_P, /* AKEYCODE_P */
+    SDL_SCANCODE_Q, /* AKEYCODE_Q */
+    SDL_SCANCODE_R, /* AKEYCODE_R */
+    SDL_SCANCODE_S, /* AKEYCODE_S */
+    SDL_SCANCODE_T, /* AKEYCODE_T */
+    SDL_SCANCODE_U, /* AKEYCODE_U */
+    SDL_SCANCODE_V, /* AKEYCODE_V */
+    SDL_SCANCODE_W, /* AKEYCODE_W */
+    SDL_SCANCODE_X, /* AKEYCODE_X */
+    SDL_SCANCODE_Y, /* AKEYCODE_Y */
+    SDL_SCANCODE_Z, /* AKEYCODE_Z */
+    SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
+    SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
+    SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
+    SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
+    SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
+    SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
+    SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
+    SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EXPLORER */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENVELOPE */
+    SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
+    SDL_SCANCODE_BACKSPACE, /* AKEYCODE_DEL */
+    SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
+    SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
+    SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
+    SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
+    SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
+    SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
+    SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
+    SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SLASH */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
+    SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
+    SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
+    SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
+    SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
+    SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
+    SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_REWIND */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_FAST_FORWARD */
+    SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
+    SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
+    SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
+    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
+};
+
+static SDL_Scancode
+TranslateKeycode(int keycode)
+{
+    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
+
+    if (keycode < SDL_arraysize(Android_Keycodes)) {
+        scancode = Android_Keycodes[keycode];
+    }
+    if (scancode == SDL_SCANCODE_UNKNOWN) {
+        __android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
+    }
+    __android_log_print(ANDROID_LOG_INFO, "SDLXELI", "keycode %d scancode %d", keycode, scancode);
+    return scancode;
+}
+
+int
+Android_OnKeyDown(int keycode)
+{
+    return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
+}
+
+int
+Android_OnKeyUp(int keycode)
+{
+    return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */