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.
This commit is contained in:
Sam Lantinga 2017-08-28 09:54:16 -07:00
parent 0560544d1c
commit c45932ba7e
1 changed files with 22 additions and 14 deletions

View File

@ -667,6 +667,21 @@ public class SDLActivity extends Activity {
return mSingleton.commandHandler.post(new ShowTextInputTask(x, y, w, h)); 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. * This method is called by SDL using JNI.
*/ */
@ -1587,23 +1602,19 @@ class DummyEdit extends View implements View.OnKeyListener {
@Override @Override
public boolean onKey(View v, int keyCode, KeyEvent event) { public boolean onKey(View v, int keyCode, KeyEvent event) {
/*
// This handles the hardware keyboard input * This handles the hardware keyboard input
if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) { */
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLActivity.isTextInputEvent(event)) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1); ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} }
return true;
}
if (event.getAction() == KeyEvent.ACTION_DOWN) {
SDLActivity.onNativeKeyDown(keyCode); SDLActivity.onNativeKeyDown(keyCode);
return true; return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) { } else if (event.getAction() == KeyEvent.ACTION_UP) {
SDLActivity.onNativeKeyUp(keyCode); SDLActivity.onNativeKeyUp(keyCode);
return true; return true;
} }
return false; return false;
} }
@ -1645,20 +1656,17 @@ class SDLInputConnection extends BaseInputConnection {
@Override @Override
public boolean sendKeyEvent(KeyEvent event) { public boolean sendKeyEvent(KeyEvent event) {
/* /*
* This handles the keycodes from soft keyboard (and IME-translated * This handles the keycodes from soft keyboard (and IME-translated input from hardkeyboard)
* input from hardkeyboard)
*/ */
int keyCode = event.getKeyCode(); int keyCode = event.getKeyCode();
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) { if (SDLActivity.isTextInputEvent(event)) {
commitText(String.valueOf((char) event.getUnicodeChar()), 1); commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} }
SDLActivity.onNativeKeyDown(keyCode); SDLActivity.onNativeKeyDown(keyCode);
return true; return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) { } else if (event.getAction() == KeyEvent.ACTION_UP) {
SDLActivity.onNativeKeyUp(keyCode); SDLActivity.onNativeKeyUp(keyCode);
return true; return true;
} }