add missing key codes to Key.isModifier, and move the information into KeyCode

This commit is contained in:
Helium314 2025-06-01 18:40:54 +02:00
parent f81f6a7f7d
commit 7499c38e13
3 changed files with 10 additions and 9 deletions

View file

@ -518,11 +518,7 @@ public class Key implements Comparable<Key> {
} }
public final boolean isModifier() { public final boolean isModifier() {
return switch (mCode) { return KeyCode.INSTANCE.isModifier(mCode);
case KeyCode.SHIFT, KeyCode.SYMBOL_ALPHA, KeyCode.ALPHA, KeyCode.SYMBOL, KeyCode.NUMPAD, KeyCode.CTRL,
KeyCode.ALT, KeyCode.FN, KeyCode.META -> true;
default -> false;
};
} }
public final boolean isRepeatable() { public final boolean isRepeatable() {

View file

@ -202,6 +202,12 @@ object KeyCode {
else -> throw IllegalStateException("key code $this not yet supported") else -> throw IllegalStateException("key code $this not yet supported")
} }
fun Int.isModifier() = when (this) {
SHIFT, SYMBOL_ALPHA, ALPHA, SYMBOL, NUMPAD, FN, CTRL, CTRL_LEFT, CTRL_RIGHT, ALT, ALT_LEFT, ALT_RIGHT,
META, META_LEFT, META_RIGHT -> true
else -> false
}
// todo: there are many more keys, see near https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_0 // todo: there are many more keys, see near https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_0
/** /**
* Convert a keyCode / codePoint to a KeyEvent.KEYCODE_<xxx>. * Convert a keyCode / codePoint to a KeyEvent.KEYCODE_<xxx>.

View file

@ -814,12 +814,11 @@ public final class InputLogic {
// {@link KeyboardSwitcher#onEvent(Event)}, or {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}. // {@link KeyboardSwitcher#onEvent(Event)}, or {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}.
// We need to switch to the shortcut IME. This is handled by LatinIME since the // We need to switch to the shortcut IME. This is handled by LatinIME since the
// input logic has no business with IME switching. // input logic has no business with IME switching.
case KeyCode.CAPS_LOCK, KeyCode.SYMBOL_ALPHA, KeyCode.ALPHA, KeyCode.SYMBOL, KeyCode.NUMPAD, KeyCode.EMOJI, case KeyCode.CAPS_LOCK, KeyCode.EMOJI, KeyCode.TOGGLE_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE:
KeyCode.TOGGLE_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE, KeyCode.FN,
KeyCode.CTRL, KeyCode.CTRL_LEFT, KeyCode.CTRL_RIGHT, KeyCode.ALT, KeyCode.ALT_LEFT, KeyCode.ALT_RIGHT,
KeyCode.META, KeyCode.META_LEFT, KeyCode.META_RIGHT:
break; break;
default: default:
if (KeyCode.INSTANCE.isModifier(event.getMKeyCode()))
return; // continuation of previous switch case, but modifiers are in a separate place
if (event.getMMetaState() != 0) { if (event.getMMetaState() != 0) {
// need to convert codepoint to KeyEvent.KEYCODE_<xxx> // need to convert codepoint to KeyEvent.KEYCODE_<xxx>
final int codeToConvert = event.getMKeyCode() < 0 ? event.getMKeyCode() : event.getMCodePoint(); final int codeToConvert = event.getMKeyCode() < 0 ? event.getMKeyCode() : event.getMCodePoint();