Simple Directmedia Layer
Go to file
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
acinclude Fix a libtool issue with some mingw-w64 cross compilers (thanks, Ozkan!). 2015-05-26 19:54:06 -04:00
android-project Fixed bug 2949 - [Android] Virtual DPAD remote not registered 2015-06-16 23:58:09 -07:00
build-scripts WinRT: made sure build script generates Release-built binaries, by default 2015-06-14 20:15:36 -04:00
cmake configure/cmake/x11: Removed SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 test. 2015-06-08 01:13:51 -04:00
debian Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
docs Excluded SDL_egl.h from doxygen input. 2015-06-16 20:25:53 +02:00
include Fixed bug 3009 - Cannot compile SDL2 on Windows 2015-06-13 10:47:55 -07:00
premake X11: Add Xdbe support to message boxes (thanks, Melker!). 2015-05-28 00:30:21 -04:00
src Fixed bug 2948 - [Android] Arrow keys from external keyboard are not received 2015-06-17 00:00:53 -07:00
test Fixed comment in test program. 2015-06-16 20:27:01 +02:00
VisualC Only use explicit inlining - otherwise Visual Studio 2010 will inline SDL_zero(info) in SDL_vsnprintf() into a memset() call when compiling the Release x64 configuration. 2015-06-14 18:57:05 -07:00
VisualC-WinRT Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
visualtest Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Xcode Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Xcode-iOS Fixed building test programs on the iOS simulator 2015-05-28 18:57:57 -07:00
.hgignore Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
Android.mk Android: Replaced spaces with tab in Android.mk file. 2015-05-06 21:11:06 +02:00
autogen.sh Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
BUGS.txt Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
cmake_uninstall.cmake.in Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
CMakeLists.txt Fixed bug 3009 - Cannot compile SDL2 on Windows 2015-06-13 10:47:55 -07:00
configure Updated configure script. 2015-06-08 01:17:58 -04:00
configure.in configure/cmake/x11: Removed SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 test. 2015-06-08 01:13:51 -04:00
COPYING.txt Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
CREDITS.txt Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
INSTALL.txt Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
Makefile.in Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
Makefile.minimal Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
Makefile.pandora Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
Makefile.psp Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
Makefile.wiz Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
README-SDL.txt Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
README.txt Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
sdl2-config.in Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
sdl2.m4 Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
sdl2.pc.in Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
SDL2.spec.in Fixed docs path in RPM .spec file. 2015-06-04 19:05:01 -04:00
TODO.txt Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
VisualC.html Windows: Always set the system timer resolution to 1ms by default. 2015-04-20 12:22:44 -04:00
WhatsNew.txt Moved entry in WhatsNew.txt because it was already in 2.0.0 for Android and iOS. 2015-06-16 20:28:21 +02:00

                         Simple DirectMedia Layer

                                  (SDL)

                                Version 2.0

---
http://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed
to provide low level access to audio, keyboard, mouse, joystick, and graphics
hardware via OpenGL and Direct3D. It is used by video playback software,
emulators, and popular games including Valve's award winning catalog
and many Humble Bundle games.

More extensive documentation is available in the docs directory, starting
with README.md

Enjoy!
	Sam Lantinga				(slouken@libsdl.org)