From c687bfa697dcb5164fb26739de2567baffd7d162 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 5 Jul 2023 15:34:18 +0300 Subject: [PATCH] [Android] Set `echo` property for the physical keyboard events. --- platform/android/android_input_handler.cpp | 3 ++- platform/android/android_input_handler.h | 2 +- .../lib/src/org/godotengine/godot/GodotLib.java | 2 +- .../godot/input/GodotInputHandler.java | 4 ++-- .../godot/input/GodotTextInputWrapper.java | 16 ++++++++-------- platform/android/java_godot_lib_jni.cpp | 4 ++-- platform/android/java_godot_lib_jni.h | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/platform/android/android_input_handler.cpp b/platform/android/android_input_handler.cpp index 37a019eaa438..8bf5eae2f8f5 100644 --- a/platform/android/android_input_handler.cpp +++ b/platform/android/android_input_handler.cpp @@ -64,7 +64,7 @@ void AndroidInputHandler::_set_key_modifier_state(Ref e } } -void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed) { +void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed, bool p_echo) { static char32_t prev_wc = 0; char32_t unicode = p_unicode; if ((p_unicode & 0xfffffc00) == 0xd800) { @@ -125,6 +125,7 @@ void AndroidInputHandler::process_key_event(int p_physical_keycode, int p_unicod ev->set_key_label(fix_key_label(p_key_label, keycode)); ev->set_unicode(fix_unicode(unicode)); ev->set_pressed(p_pressed); + ev->set_echo(p_echo); _set_key_modifier_state(ev, keycode); diff --git a/platform/android/android_input_handler.h b/platform/android/android_input_handler.h index 42d1c228a8d0..c74c5020e309 100644 --- a/platform/android/android_input_handler.h +++ b/platform/android/android_input_handler.h @@ -101,7 +101,7 @@ class AndroidInputHandler { void process_magnify(Point2 p_pos, float p_factor); void process_pan(Point2 p_pos, Vector2 p_delta); void process_joy_event(JoypadEvent p_event); - void process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed); + void process_key_event(int p_physical_keycode, int p_unicode, int p_key_label, bool p_pressed, bool p_echo); }; #endif // ANDROID_INPUT_HANDLER_H diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index c725b1a7c9a8..b9ecd6971d95 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -147,7 +147,7 @@ public static native boolean initialize(Activity activity, /** * Forward regular key events. */ - public static native void key(int p_physical_keycode, int p_unicode, int p_key_label, boolean p_pressed); + public static native void key(int p_physical_keycode, int p_unicode, int p_key_label, boolean p_pressed, boolean p_echo); /** * Forward game device's key events. diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java index 317344f2a531..185d03fe3964 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java @@ -141,7 +141,7 @@ public boolean onKeyUp(final int keyCode, KeyEvent event) { final int physical_keycode = event.getKeyCode(); final int unicode = event.getUnicodeChar(); final int key_label = event.getDisplayLabel(); - GodotLib.key(physical_keycode, unicode, key_label, false); + GodotLib.key(physical_keycode, unicode, key_label, false, event.getRepeatCount() > 0); }; return true; @@ -176,7 +176,7 @@ public boolean onKeyDown(final int keyCode, KeyEvent event) { final int physical_keycode = event.getKeyCode(); final int unicode = event.getUnicodeChar(); final int key_label = event.getDisplayLabel(); - GodotLib.key(physical_keycode, unicode, key_label, true); + GodotLib.key(physical_keycode, unicode, key_label, true, event.getRepeatCount() > 0); } return true; diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java index f48dba56df21..06b565c30ff2 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java @@ -93,8 +93,8 @@ public void afterTextChanged(final Editable s) { @Override public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) { for (int i = 0; i < count; ++i) { - GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, true); - GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, false); + GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, true, false); + GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, false, false); if (mHasSelection) { mHasSelection = false; @@ -115,8 +115,8 @@ public void onTextChanged(final CharSequence pCharSequence, final int start, fin // Return keys are handled through action events continue; } - GodotLib.key(0, character, 0, true); - GodotLib.key(0, character, 0, false); + GodotLib.key(0, character, 0, true, false); + GodotLib.key(0, character, 0, false, false); } } @@ -127,8 +127,8 @@ public boolean onEditorAction(final TextView pTextView, final int pActionID, fin if (characters != null) { for (int i = 0; i < characters.length(); i++) { final int character = characters.codePointAt(i); - GodotLib.key(0, character, 0, true); - GodotLib.key(0, character, 0, false); + GodotLib.key(0, character, 0, true, false); + GodotLib.key(0, character, 0, false, false); } } } @@ -136,8 +136,8 @@ public boolean onEditorAction(final TextView pTextView, final int pActionID, fin if (pActionID == EditorInfo.IME_ACTION_DONE) { // Enter key has been pressed mRenderView.queueOnRenderThread(() -> { - GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, true); - GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, false); + GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, true, false); + GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, false, false); }); mRenderView.getView().requestFocus(); return true; diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 7c1b6023c772..b54491e0e1f7 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -385,11 +385,11 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged( } // Called on the UI thread -JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed) { +JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed, jboolean p_echo) { if (step.get() <= 0) { return; } - input_handler->process_key_event(p_physical_keycode, p_unicode, p_key_label, p_pressed); + input_handler->process_key_event(p_physical_keycode, p_unicode, p_key_label, p_pressed, p_echo); } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) { diff --git a/platform/android/java_godot_lib_jni.h b/platform/android/java_godot_lib_jni.h index 9158e89c139c..ee6a19034c0c 100644 --- a/platform/android/java_godot_lib_jni.h +++ b/platform/android/java_godot_lib_jni.h @@ -49,7 +49,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchMouseEvent(JN JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_dispatchTouchEvent(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jboolean p_double_tap); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnify(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_factor); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_pan(JNIEnv *env, jclass clazz, jfloat p_x, jfloat p_y, jfloat p_delta_x, jfloat p_delta_y); -JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed); +JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_physical_keycode, jint p_unicode, jint p_key_label, jboolean p_pressed, jboolean p_echo); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y);