1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Cleanup and unify keyboard input.

- Unify keycode values (secondary label printed on a key), remove unused hardcoded Latin-1 codes.
- Unify IME behaviour, add inline composition string display on Windows and X11.
- Add key_label (localized label printed on a key) value to the key events, and allow mapping actions to the unshifted Unicode events.
- Add support for physical keyboard (Bluetooth or Sidecar) handling on iOS.
- Add support for media key handling on macOS.

Co-authored-by: Raul Santos <raulsntos@gmail.com>
This commit is contained in:
bruvzg
2022-12-11 01:21:22 +02:00
parent 9937915ad7
commit daad4aed62
61 changed files with 4464 additions and 3655 deletions

View File

@@ -148,7 +148,7 @@ public class GodotLib {
/**
* Forward regular key events.
*/
public static native void key(int p_keycode, int p_physical_keycode, int p_unicode, boolean p_pressed);
public static native void key(int p_physical_keycode, int p_unicode, int p_key_label, boolean p_pressed);
/**
* Forward game device's key events.

View File

@@ -129,12 +129,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
}
} else {
// 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);
final int key_label = event.getDisplayLabel();
GodotLib.key(physical_keycode, unicode, key_label, false);
};
return true;
@@ -166,10 +164,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
GodotLib.joybutton(godotJoyId, button, true);
}
} else {
final int keycode = event.getUnicodeChar(0);
final int physical_keycode = event.getKeyCode();
final int unicode = event.getUnicodeChar();
GodotLib.key(keycode, physical_keycode, unicode, true);
final int key_label = event.getDisplayLabel();
GodotLib.key(physical_keycode, unicode, key_label, true);
}
return true;

View File

@@ -93,8 +93,8 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@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(0, KeyEvent.KEYCODE_DEL, 0, true);
GodotLib.key(0, KeyEvent.KEYCODE_DEL, 0, false);
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, true);
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, 0, false);
if (mHasSelection) {
mHasSelection = false;
@@ -110,13 +110,13 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
newChars[i - start] = pCharSequence.charAt(i);
}
for (int i = 0; i < count; ++i) {
int key = newChars[i];
if ((key == '\n') && !(mEdit.getKeyboardType() == GodotEditText.VirtualKeyboardType.KEYBOARD_TYPE_MULTILINE)) {
final int character = newChars[i];
if ((character == '\n') && !(mEdit.getKeyboardType() == GodotEditText.VirtualKeyboardType.KEYBOARD_TYPE_MULTILINE)) {
// Return keys are handled through action events
continue;
}
GodotLib.key(key, 0, key, true);
GodotLib.key(key, 0, key, false);
GodotLib.key(0, character, 0, true);
GodotLib.key(0, character, 0, false);
}
}
@@ -126,17 +126,17 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
final String characters = pKeyEvent.getCharacters();
for (int i = 0; i < characters.length(); i++) {
final int ch = characters.codePointAt(i);
GodotLib.key(ch, 0, ch, true);
GodotLib.key(ch, 0, ch, false);
final int character = characters.codePointAt(i);
GodotLib.key(0, character, 0, true);
GodotLib.key(0, character, 0, false);
}
}
if (pActionID == EditorInfo.IME_ACTION_DONE) {
// Enter key has been pressed
mRenderView.queueOnRenderThread(() -> {
GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, true);
GodotLib.key(0, KeyEvent.KEYCODE_ENTER, 0, false);
GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, true);
GodotLib.key(KeyEvent.KEYCODE_ENTER, 0, 0, false);
});
mRenderView.getView().requestFocus();
return true;