You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Fix incorrect Android scancodes
This commit is contained in:
@@ -135,7 +135,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_scancode, int p_physical_scancode, int p_unicode, boolean p_pressed);
|
||||
|
||||
/**
|
||||
* Forward game device's key events from the main thread to the GL thread.
|
||||
|
||||
@@ -96,9 +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.
|
||||
// getScanCode(): Hardware key id. Device dependent and only used for debugging.
|
||||
// Godot's scancodes match the ASCII codes, so for single byte unicode characters,
|
||||
// we can use the unmodified unicode character to determine Godot's scancode.
|
||||
final int scancode = event.getUnicodeChar(0);
|
||||
final int physical_scancode = event.getKeyCode();
|
||||
final int unicode = event.getUnicodeChar();
|
||||
GodotLib.key(scancode, physical_scancode, unicode, false);
|
||||
};
|
||||
|
||||
return true;
|
||||
@@ -131,9 +136,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 scancode = event.getUnicodeChar(0);
|
||||
final int physical_scancode = event.getKeyCode();
|
||||
final int unicode = event.getUnicodeChar();
|
||||
GodotLib.key(scancode, physical_scancode, unicode, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -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
|
||||
mView.queueEvent(() -> {
|
||||
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);
|
||||
});
|
||||
mView.requestFocus();
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user