SDL/src
Sam Lantinga 3779bf3845 Fixed bug 2948 - [Android] Arrow keys from external keyboard are not received
Sylvain

http://developer.android.com/reference/android/view/InputDevice.html
 int SOURCE_CLASS_JOYSTICK   Constant Value: 16       (0x00000010)

 int SOURCE_JOYSTICK         Constant Value: 16777232 (0x01000010)
 int SOURCE_KEYBOARD         Constant Value: 257      (0x00000101)
 int SOURCE_GAMEPAD          Constant Value: 1025     (0x00000401)
 int SOURCE_DPAD             Constant Value:  513     (0x00000201)


I have an a PC keyboard that I connect to an android device.
The issue is that "arrow" keys gets lost.

More explanation:

This device gets detected twice by the java "pollInputDevices()" both as SOURCE_KEYBOARD and as a composite (0x1000311 == SOURCE_JOYSTICK | SOURCE_KEYBOARD | SOURCE_DPAD).
Because of being a SOURCE_CLASS_JOYSTICK, only the second entry is registered, and I opened it.


When I press one arrow key, the java method "onKey(...)" is called.
The Source "event.getSource()" is "SOURCE_KEYBOARD", so it enters this conditions :

   if ( (event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0 ||
      (event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {


And then, it enters :

   SDLActivity.onNativePadDown() (native code in "SDL_sysjoystick.c")


Since the "arrows" are viewed as "D-PAD", it gets translated :

   int button = keycode_to_SDL(keycode);


But the android-java "event.getDeviceId()" is wrong: this is the one from the Keyboard, and not the one from the Joystick that I have opened.
So I don't get them through the Joystick interface.


And since, the keycode has been translated, it returns 0 and assume it was consumed.
So I lost the key in the function "Android_OnPadDown()"


Notice, It won't happen with other normal "letters" keys because they does not get translated by "keycode_to_SDL", so "Android_OnPadDown()" returns -1.
And then java code send the keys to "SDLActivity.onNativeKeyDown()".




Possible patch on "Android_OnPadDown" and also "Android_OnPadUp" (and maybe other functons):

85 int
186 Android_OnPadDown(int device_id, int keycode)
187 {
188     SDL_joylist_item *item;
189     int button = keycode_to_SDL(keycode);
190     if (button >= 0) {
191         item = JoystickByDeviceId(device_id);
192         if (item && item->joystick) {
193             SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
194         }
+           else return -1;
195         return 0;
196     }
197
198     return -1;
199 }

It would allow the java caller function to send the key to "SDLActivity.onNativeKeyDown();"



Another solution, would be to replace:

 if ( (event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0 ||
      (event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {

by

 if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0)

Because only "SOURCE_CLASS_JOYSTICK" devices are registered/opened.
2015-06-17 00:00:53 -07:00
..
atomic Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
audio AIX: Fixed nearly impossible file descriptor leak. 2015-06-04 17:52:51 +02:00
core Make some string literals "const char *", not "char *" (thanks, Martin!). 2015-06-12 11:58:31 -04:00
cpuinfo Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
dynapi Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
events Fixed crash if allocation for touch device failed. 2015-06-12 21:10:31 +02:00
file Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
filesystem Windows SDL_GetBasePath: free string on failure. 2015-05-28 15:36:27 -04:00
haptic Haptic/Linux: Keep track of device numbers properly to track duplicates. 2015-06-16 00:57:45 -04:00
joystick Fixed bug 2948 - [Android] Arrow keys from external keyboard are not received 2015-06-17 00:00:53 -07:00
libm Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
loadso Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
main Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
power Linux: Implemented sysfs-based version of SDL_GetPowerInfo(). 2015-06-03 13:11:28 -07:00
render Fixed bug 2908 - Fix clang warnings 2015-06-14 19:10:51 -07:00
stdlib Let's assume that if VS2005 and VS2010 do it, VS2008 probably does, too. 2015-06-07 20:00:20 -04:00
test Some setups need _GNU_SOURCE to make LLONG_MAX available (thanks, Ozkan!). 2015-05-26 16:31:11 -04:00
thread Fixed bug 3011 - pthread/SDL_syssem.c requires _GNU_SOURCE 2015-06-13 13:36:47 -07:00
timer Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
video Fixed bug 3015 - grab mouse inconsistent state 2015-06-15 23:44:08 -07:00
SDL.c Stack hint should look for 0, not -1, and not care about environment variables. 2015-05-26 21:19:23 -04:00
SDL_assert.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_assert_c.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_error.c Fixed bug 2210 - Initializing Video produces unnecessary errors 2015-05-28 12:31:25 -07:00
SDL_error_c.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_hints.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_internal.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_log.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00