Fixed bug 2277 - Hardware keyboard control key sequences don't get reported chw Control key sequences from hardware keyboards (wireless/USB/bluetooth) get not properly reported on Android devices. The attached patch uses the idea from http://stackoverflow.com/questions/12337117/capture-all-ctrl-under-android to make control key sequences appear as normal SDL_KEYDOWN events instead of cooked text input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index 7420714..aa232dc 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -667,6 +667,21 @@ public class SDLActivity extends Activity {
return mSingleton.commandHandler.post(new ShowTextInputTask(x, y, w, h));
}
+ public static boolean isTextInputEvent(KeyEvent event) {
+
+ // Key pressed with Ctrl should be sent as SDL_KEYDOWN/SDL_KEYUP and not SDL_TEXTINPUT
+ if (android.os.Build.VERSION.SDK_INT >= 11) {
+ if (event.isCtrlPressed()) {
+ return false;
+ }
+ }
+
+ if (event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE) {
+ return true;
+ }
+ return false;
+ }
+
/**
* This method is called by SDL using JNI.
*/
@@ -1587,23 +1602,19 @@ class DummyEdit extends View implements View.OnKeyListener {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
-
- // This handles the hardware keyboard input
- if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) {
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ /*
+ * This handles the hardware keyboard input
+ */
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ if (SDLActivity.isTextInputEvent(event)) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
- return true;
- }
-
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
SDLActivity.onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
SDLActivity.onNativeKeyUp(keyCode);
return true;
}
-
return false;
}
@@ -1645,20 +1656,17 @@ class SDLInputConnection extends BaseInputConnection {
@Override
public boolean sendKeyEvent(KeyEvent event) {
-
/*
- * This handles the keycodes from soft keyboard (and IME-translated
- * input from hardkeyboard)
+ * This handles the keycodes from soft keyboard (and IME-translated input from hardkeyboard)
*/
int keyCode = event.getKeyCode();
if (event.getAction() == KeyEvent.ACTION_DOWN) {
- if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) {
+ if (SDLActivity.isTextInputEvent(event)) {
commitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
SDLActivity.onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
-
SDLActivity.onNativeKeyUp(keyCode);
return true;
}