Skip to content

Commit

Permalink
Fixed bug 2277 - Hardware keyboard control key sequences don't get re…
Browse files Browse the repository at this point in the history
…ported

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.
  • Loading branch information
slouken committed Aug 28, 2017
1 parent 0560544 commit c45932b
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -667,6 +667,21 @@ public static boolean showTextInput(int x, int y, int w, int 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.
*/
Expand Down Expand Up @@ -1587,23 +1602,19 @@ public boolean onCheckIsTextEditor() {

@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;
}

Expand Down Expand Up @@ -1645,20 +1656,17 @@ public SDLInputConnection(View targetView, boolean fullEditor) {

@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;
}
Expand Down

0 comments on commit c45932b

Please sign in to comment.