feat: support hardware keyboard input, including numpad keys#305
Open
MiMoHo wants to merge 1 commit into
Open
Conversation
The calculator had no hardware-key handling, so digits/operators from a physical or numpad keyboard were silently dropped. Add an onKeyDown handler that routes both the top-row and numpad key codes (digits, + - * /, =, Enter, decimal, backspace, clear) to the same actions as the on-screen buttons. Unhandled keys fall through to super.
56a964f to
a406d57
Compare
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.
Type of change(s)
What changed and why
The Calculator had no hardware-keyboard handling at all —
MainActivityonly wired the on-screen button click listeners, and the formula/result views are non-editableAutofitTextViews (no IME path). So every key event from a physical/numpad keyboard (the case reported in #134, e.g. an 8BitDo/Clicks numpad) was silently dropped, whether top-rowKEYCODE_0..9orKEYCODE_NUMPAD_*.Fix: add an
onKeyDownoverride that maps both the top-row and numpad key codes — digits,+ − × ÷,=, Enter, decimal, backspace, clear — to the exact samecalc.*calls the on-screen buttons already use (numpadClicked,handleOperation,handleEquals,handleClear,handleReset). Any unrecognized key falls through tosuper.onKeyDown, so no existing behavior changes.Tests performed
Built
fossDebug, installed on an Android 15 (API 35) emulator, drove input viaadb shell input keyevent:7 8,NUMPAD_ADD,2,NUMPAD_ENTER→ evaluates correctly.ESCresets the display to0; thenNUMPAD_5,NUMPAD_MULTIPLY,NUMPAD_3,NUMPAD_ENTER→5×3 = 15.KEYCODE_7/8/9) enter digits;KEYCODE_DELdeletes the last character (backspace).Closes the following issue(s)
Checklist
CHANGELOG.md.Coded with Opus 4.8 ultracode.