Skip to content

Commit

Permalink
Merge pull request #79089 from bruvzg/android_echo
Browse files Browse the repository at this point in the history
[Android] Set `echo` property for the physical keyboard events.
  • Loading branch information
YuriSizov committed Jul 12, 2023
2 parents aa353df + c687bfa commit 64689c1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion platform/android/android_input_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void AndroidInputHandler::_set_key_modifier_state(Ref<InputEventWithModifiers> 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) {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion platform/android/android_input_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -127,17 +127,17 @@ 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);
}
}
}

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;
Expand Down
4 changes: 2 additions & 2 deletions platform/android/java_godot_lib_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion platform/android/java_godot_lib_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 64689c1

Please sign in to comment.