If I set targetSdkVersion higher than 15, Monkey stops receiving key events from backspace on software keyboard.
Here is what worked for me on Nexus 7 (Android 6). Replace the following code in monkey/targets/android/modules/native/androidgame.java
public InputConnection onCreateInputConnection( EditorInfo outAttrs ){
//voodoo to disable various undesirable soft keyboard features such as predictive text and fullscreen mode.
outAttrs.inputType=InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
outAttrs.imeOptions=EditorInfo.IME_FLAG_NO_FULLSCREEN|EditorInfo.IME_FLAG_NO_EXTRACT_UI;
return null;
}
with this
public InputConnection onCreateInputConnection( EditorInfo outAttrs ){
//voodoo to disable various undesirable soft keyboard features such as predictive text and fullscreen mode.
outAttrs.inputType=InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
outAttrs.imeOptions=EditorInfo.IME_FLAG_NO_FULLSCREEN|EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.initialSelStart = -1;
outAttrs.initialSelEnd = -1;
return new BackspaceInputConnection(this, false);
}
private class BackspaceInputConnection extends BaseInputConnection {
public BackspaceInputConnection(View targetView, boolean fullEditor) {
super(targetView, fullEditor);
}
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
if (beforeLength == 1 && afterLength == 0) {
return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
&& super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
}
return super.deleteSurroundingText(beforeLength, afterLength);
}
}
|