Skip to content

Commit e19a56f

Browse files
committed
Don't send fake key events while processing real ones on Android
Fixes #11350
1 parent 1ab6163 commit e19a56f

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public enum NativeState {
231231
protected static boolean mSDLMainFinished = false;
232232
protected static boolean mActivityCreated = false;
233233
private static SDLFileDialogState mFileDialogState = null;
234+
protected static boolean mDispatchingKeyEvent = false;
234235

235236
protected static SDLGenericMotionListener_API14 getMotionListener() {
236237
if (mMotionListener == null) {
@@ -807,7 +808,14 @@ public boolean dispatchKeyEvent(KeyEvent event) {
807808
) {
808809
return false;
809810
}
810-
return super.dispatchKeyEvent(event);
811+
mDispatchingKeyEvent = true;
812+
boolean result = super.dispatchKeyEvent(event);
813+
mDispatchingKeyEvent = false;
814+
return result;
815+
}
816+
817+
public static boolean dispatchingKeyEvent() {
818+
return mDispatchingKeyEvent;
811819
}
812820

813821
/* Transition to next state */
@@ -1507,14 +1515,15 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC
15071515
}
15081516

15091517
if (event.getAction() == KeyEvent.ACTION_DOWN) {
1518+
onNativeKeyDown(keyCode);
1519+
15101520
if (isTextInputEvent(event)) {
15111521
if (ic != null) {
15121522
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
15131523
} else {
15141524
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
15151525
}
15161526
}
1517-
onNativeKeyDown(keyCode);
15181527
return true;
15191528
} else if (event.getAction() == KeyEvent.ACTION_UP) {
15201529
onNativeKeyUp(keyCode);

android-project/app/src/main/java/org/libsdl/app/SDLInputConnection.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,20 @@ protected void updateText() {
111111

112112
if (matchLength < text.length()) {
113113
String pendingText = text.subSequence(matchLength, text.length()).toString();
114-
for (offset = 0; offset < pendingText.length(); ) {
115-
int codePoint = pendingText.codePointAt(offset);
116-
if (codePoint == '\n') {
117-
if (SDLActivity.onNativeSoftReturnKey()) {
118-
return;
114+
if (!SDLActivity.dispatchingKeyEvent()) {
115+
for (offset = 0; offset < pendingText.length(); ) {
116+
int codePoint = pendingText.codePointAt(offset);
117+
if (codePoint == '\n') {
118+
if (SDLActivity.onNativeSoftReturnKey()) {
119+
return;
120+
}
119121
}
122+
/* Higher code points don't generate simulated scancodes */
123+
if (codePoint > 0 && codePoint < 128) {
124+
nativeGenerateScancodeForUnichar((char)codePoint);
125+
}
126+
offset += Character.charCount(codePoint);
120127
}
121-
/* Higher code points don't generate simulated scancodes */
122-
if (codePoint < 128) {
123-
nativeGenerateScancodeForUnichar((char)codePoint);
124-
}
125-
offset += Character.charCount(codePoint);
126128
}
127129
SDLInputConnection.nativeCommitText(pendingText, 0);
128130
}

0 commit comments

Comments
 (0)