diff options
author | Marcel Admiraal <madmiraal@users.noreply.github.com> | 2022-07-10 12:32:01 +0100 |
---|---|---|
committer | Marcel Admiraal <madmiraal@users.noreply.github.com> | 2022-07-13 16:24:01 +0100 |
commit | 6661141c21427e4b529884a71f092f0f2010aa31 (patch) | |
tree | cd9dda34da288be18f418416e28e080d9f50d3bf /platform/android/java/lib/src | |
parent | dc5a6362c17b3a2bdae13e40ce9c5b6fa990e04e (diff) |
Fix incorrect Android scancodes
Diffstat (limited to 'platform/android/java/lib/src')
3 files changed, 21 insertions, 20 deletions
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 e2ae62d9cf..f855fc6cf6 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -151,7 +151,7 @@ public class GodotLib { /** * Forward regular key events from the main thread to the GL thread. */ - public static native void key(int p_keycode, int p_scancode, int p_unicode_char, boolean p_pressed); + public static native void key(int p_keycode, int p_physical_keycode, int p_unicode, boolean p_pressed); /** * Forward game device's key events from the main thread to the GL thread. 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 ccfb865b1a..da15b2490c 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 @@ -96,10 +96,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener { GodotLib.joybutton(godotJoyId, button, false); } } else { - final int scanCode = event.getScanCode(); - final int chr = event.getUnicodeChar(0); - GodotLib.key(keyCode, scanCode, chr, false); - } + // getKeyCode(): The physical key that was pressed. + // Godot's keycodes match the ASCII codes, so for single byte unicode characters, + // we can use the unmodified unicode character to determine Godot's keycode. + final int keycode = event.getUnicodeChar(0); + final int physical_keycode = event.getKeyCode(); + final int unicode = event.getUnicodeChar(); + GodotLib.key(keycode, physical_keycode, unicode, false); + }; return true; } @@ -131,9 +135,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener { GodotLib.joybutton(godotJoyId, button, true); } } else { - final int scanCode = event.getScanCode(); - final int chr = event.getUnicodeChar(0); - GodotLib.key(keyCode, scanCode, chr, true); + final int keycode = event.getUnicodeChar(0); + final int physical_keycode = event.getKeyCode(); + final int unicode = event.getUnicodeChar(); + GodotLib.key(keycode, physical_keycode, unicode, true); } 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 e940aafa9e..5882753e9d 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 @@ -92,11 +92,9 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene @Override public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) { - //Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after); - for (int i = 0; i < count; ++i) { - GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true); - GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false); + GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, true); + GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, false); if (mHasSelection) { mHasSelection = false; @@ -107,8 +105,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene @Override public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) { - //Log.d(TAG, "onTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",before: " + before); - final int[] newChars = new int[count]; for (int i = start; i < start + count; ++i) { newChars[i - start] = pCharSequence.charAt(i); @@ -119,8 +115,8 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene // Return keys are handled through action events continue; } - GodotLib.key(0, 0, key, true); - GodotLib.key(0, 0, key, false); + GodotLib.key(key, 0, key, true); + GodotLib.key(key, 0, key, false); } } @@ -131,16 +127,16 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene for (int i = 0; i < characters.length(); i++) { final int ch = characters.codePointAt(i); - GodotLib.key(0, 0, ch, true); - GodotLib.key(0, 0, ch, false); + GodotLib.key(ch, 0, ch, true); + GodotLib.key(ch, 0, ch, false); } } if (pActionID == EditorInfo.IME_ACTION_DONE) { // Enter key has been pressed mRenderView.queueOnRenderThread(() -> { - GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, true); - GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, false); + GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, true); + GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, false); }); mRenderView.getView().requestFocus(); return true; |