Repository navigation
android: map the rest of the hardware-keyboard keycodes - #630
Merged
Merged
Conversation
The translation table only covered letters, digits, arrows, Enter, Tab, Space, Backspace, Shift / Alt, comma + period — which means a hardware keyboard on Android (tablet + Bluetooth / USB / Magic Keyboard; ChromeOS; Stage Manager iPad with a Mac keyboard) couldn't reach the host app with most of its keys. Adds the keys that have a clear semantic and a matching `KeyCode` variant: - Modifiers: Ctrl L/R, Meta L/R (Cmd on Apple keyboards), CapsLock, NumLock, ScrollLock. PR not-fl3#403 already wired the `KeyMods` tracking for Ctrl / Super, but that's a no-op as long as the keycodes themselves translate to `KeyCode::Unknown`. - Edit cluster: Escape, Insert, Delete (`KEYCODE_FORWARD_DEL`, distinct from the existing `KEYCODE_DEL` → Backspace), MoveHome, MoveEnd, PageUp, PageDown, PrintScreen / Pause. - Punctuation: `=`, `[`, `]`, `\\`, `;`, `/`, backtick. - Menu (KEYCODE_MENU, the soft-menu / context-menu key on tablets). - F1–F12. - Numpad: 0–9 + the four arithmetic ops + dot + Enter + equals. Keeps the existing `KEYCODE_HOME` (0x03) entry that maps the device home button to `KeyCode::Home`; in practice that keycode doesn't reach app input anyway and the new `KEYCODE_MOVE_HOME` (0x7a) maps to the same variant for the cursor-home case. Verified on a Pixel Tablet AVD against `is_key_pressed(Escape)`, `is_key_down(LeftControl)`, and `is_key_pressed(KpEnter)`.
Owner
|
Thanks for PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Android keycode translation table in
src/native/android/keycodes.rscoveredletters, digits, arrows, Enter, Tab, Space, Backspace, Shift / Alt, and the two
punctuation keys (comma, period). Most other keys an Android hardware keyboard
sends arrived as
KeyCode::Unknown, which means tablet-with-keyboard, ChromeOS,and Stage-Manager-iPad-with-a-Mac-keyboard setups couldn't reach the host app
with
Escape,Ctrl,Meta/Super, function keys, the numpad,Insert/Delete/PageUp/PageDown/Home/End, or several common punctuationkeys, even though
KeyCodevariants for all of them already exist.The Ctrl/Super issue is particularly visible: #403 wired
KeyModstracking forthose modifiers, but as long as
KEYCODE_CTRL_LEFT/KEYCODE_META_LEFTtranslate to
KeyCode::Unknown, the modifier state stays at default.This PR adds entries for the keys that have an obvious one-to-one mapping with
an existing
KeyCodevariant. Specifically:Ctrl L/R,Meta L/R(Cmd on Apple keyboards),CapsLock,NumLock,ScrollLock.Escape,Insert,Delete(KEYCODE_FORWARD_DEL,distinct from the existing
KEYCODE_DEL→Backspace),MoveHome,MoveEnd,PageUp,PageDown,PrintScreen(SYSRQ),Pause(BREAK).=,[,],\,;,/, backtick. (Apostrophe and minushave no matching variant in
KeyCodeso I left them out.)KEYCODE_MENU, the soft-menu / context-menu key on tablets).F1–F12.0–9plus the four arithmetic ops, dot,Enter, and=.The existing
KEYCODE_HOME(0x03) entry that maps the device home button toKeyCode::Homeis kept — that keycode doesn't reach apps in practice, and thenew
KEYCODE_MOVE_HOME(0x7a) maps to the same variant for the cursor-homecase, which is the one apps usually want.
I added trailing
// KEYCODE_*comments on the previously-mapped lines so thetable is self-explanatory at a glance.
Test plan
cargo check --target aarch64-linux-android— clean.[patch.crates-io] miniquad = { path = "…" }override, deployed to aPixel-Tablet AVD, and confirmed via
adb shell input keyevent KEYCODE_ESCAPEthat the host app'sis_key_pressed(KeyCode::Escape)check now fires.
🤖 Generated with Claude Code