8000 android: map the rest of the hardware-keyboard keycodes by benface · Pull Request #630 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content

android: map the rest of the hardware-keyboard keycodes - #630

Merged
not-fl3 merged 1 commit into
not-fl3:masterfrom
benface:android-keycodes-completion
May 20, 2026
Merged

not-fl3 merged 1 commit into
not-fl3:masterfrom
benface:android-keycodes-completion

Conversation

@benface
@benface benface commented May 19, 2026
Copy link
Copy Markdown
Contributor

Summary

The Android keycode translation table in src/native/android/keycodes.rs covered
letters, 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 punctuation
keys, even though KeyCode variants for all of them already exist.

The Ctrl/Super issue is particularly visible: #403 wired KeyMods tracking for
those modifiers, but as long as KEYCODE_CTRL_LEFT / KEYCODE_META_LEFT
translate 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 KeyCode variant. Specifically:

  • Modifiers: Ctrl L/R, Meta L/R (Cmd on Apple keyboards), CapsLock,
    NumLock, ScrollLock.
  • Edit cluster: Escape, Insert, Delete (KEYCODE_FORWARD_DEL,
    distinct from the existing KEYCODE_DEL → Backspace), MoveHome,
    MoveEnd, PageUp, PageDown, PrintScreen (SYSRQ), Pause (BREAK).
  • Punctuation: =, [, ], \, ;, /, backtick. (Apostrophe and minus
    have no matching variant in KeyCode so I left them out.)
  • Menu (KEYCODE_MENU, the soft-menu / context-menu key on tablets).
  • F1–F12.
  • Numpad: 0–9 plus the four arithmetic ops, dot, Enter, and =.

The existing KEYCODE_HOME (0x03) entry that maps the device home button to
KeyCode::Home is kept — that keycode doesn't reach apps in practice, and the
new KEYCODE_MOVE_HOME (0x7a) maps to the same variant for the cursor-home
case, which is the one apps usually want.

I added trailing // KEYCODE_* comments on the previously-mapped lines so the
table is self-explanatory at a glance.

Test plan

  • cargo check --target aarch64-linux-android — clean.
  • Built a downstream app (CHOMP) against this branch with a
    [patch.crates-io] miniquad = { path = "…" } override, deployed to a
    Pixel-Tablet AVD, and confirmed via adb shell input keyevent KEYCODE_ESCAPE that the host app's is_key_pressed(KeyCode::Escape)
    check now fires.
  • Reviewers' usual sanity-build matrix.

🤖 Generated with Claude Code

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)`.
@not-fl3
not-fl3 merged commit 7be0d46 into not-fl3:master May 20, 2026
11 checks passed
@not-fl3
not-fl3 commented May 20, 2026
Copy link
Copy Markdown
Owner

Thanks for PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0