You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Merge pull request #80932 from m4gr3d/fix_hardware_keyboard_input_routing_main
Fix Android input routing logic when using a hardware keyboard
This commit is contained in:
@@ -33,6 +33,7 @@ package org.godotengine.godot.input;
|
|||||||
import org.godotengine.godot.*;
|
import org.godotengine.godot.*;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.text.InputFilter;
|
import android.text.InputFilter;
|
||||||
@@ -209,6 +210,13 @@ public class GodotEditText extends EditText {
|
|||||||
mRenderView.getView().requestFocus();
|
mRenderView.getView().requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When a hardware keyboard is connected, all key events come through so we can route them
|
||||||
|
// directly to the engine.
|
||||||
|
// This is not the case when using a soft keyboard, requiring extra processing from this class.
|
||||||
|
if (hasHardwareKeyboard()) {
|
||||||
|
return mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent);
|
||||||
|
}
|
||||||
|
|
||||||
// pass event to godot in special cases
|
// pass event to godot in special cases
|
||||||
if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent)) {
|
if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -219,6 +227,13 @@ public class GodotEditText extends EditText {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
|
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
|
||||||
|
// When a hardware keyboard is connected, all key events come through so we can route them
|
||||||
|
// directly to the engine.
|
||||||
|
// This is not the case when using a soft keyboard, requiring extra processing from this class.
|
||||||
|
if (hasHardwareKeyboard()) {
|
||||||
|
return mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent);
|
||||||
|
}
|
||||||
|
|
||||||
if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent)) {
|
if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -235,10 +250,20 @@ public class GodotEditText extends EditText {
|
|||||||
isModifiedKey;
|
isModifiedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasHardwareKeyboard() {
|
||||||
|
Configuration config = getResources().getConfiguration();
|
||||||
|
return config.keyboard != Configuration.KEYBOARD_NOKEYS &&
|
||||||
|
config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Methods
|
// Methods
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
public void showKeyboard(String p_existing_text, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
public void showKeyboard(String p_existing_text, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||||
|
if (hasHardwareKeyboard()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int maxInputLength = (p_max_input_length <= 0) ? Integer.MAX_VALUE : p_max_input_length;
|
int maxInputLength = (p_max_input_length <= 0) ? Integer.MAX_VALUE : p_max_input_length;
|
||||||
if (p_cursor_start == -1) { // cursor position not given
|
if (p_cursor_start == -1) { // cursor position not given
|
||||||
this.mOriginText = p_existing_text;
|
this.mOriginText = p_existing_text;
|
||||||
@@ -262,6 +287,10 @@ public class GodotEditText extends EditText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hideKeyboard() {
|
public void hideKeyboard() {
|
||||||
|
if (hasHardwareKeyboard()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Message msg = new Message();
|
final Message msg = new Message();
|
||||||
msg.what = HANDLER_CLOSE_IME_KEYBOARD;
|
msg.what = HANDLER_CLOSE_IME_KEYBOARD;
|
||||||
msg.obj = this;
|
msg.obj = this;
|
||||||
|
|||||||
Reference in New Issue
Block a user