web: suppress the browser default on held-key auto-repeats#262
Merged
Conversation
The keydown handler bailed out on e.repeat before reaching preventDefault, so while the initial press of a captured key was consumed, every auto-repeat fell through to the browser and its default action fired - holding a cursor key scrolled the page under the game. Skipping repeats is still right for the emulator side (the Amiga keyboard sends one down code per press; the guest OS does its own key repeat), so track which codes the first keydown consumed and call preventDefault on their repeats without re-forwarding them. The keyup handler clears the entry, which also covers a hold that survives a focus loss.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a web-input regression where holding certain keys (e.g., Arrow keys / Space) caused the browser to scroll the page during emulator sessions because repeated keydown events were not consistently preventDefault()’d.
Changes:
- Add
consumedKeystracking sokeydownauto-repeat can be suppressed in the browser without re-forwarding repeats into the emulator. - Update
keyuphandling to clear consumed key tracking and suppress defaults when appropriate.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A hold that spans an emulator stop skipped the keyup delete behind the running check, and a hold broken by a focus loss gets no keyup at all. Delete before the running check on keyup, and let a non-repeat keydown that consumes nothing clear any leftover entry for its code, so the set corrects itself no matter how a hold ends.
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
Holding a cursor key in a browser session scrolled the page under the game. The
keydownhandler intry.jsreturned early one.repeatbefore reachingpreventDefault(), so only the initial press of a captured key was consumed - every auto-repeat keydown fell through to the browser, whose default action for ArrowUp/ArrowDown (and Space/PageUp/PageDown) is scrolling.Skipping repeats remains correct for the emulator side: the Amiga keyboard sends one down code per press and the guest OS performs its own key repeat, so repeats must not be re-forwarded to the keyboard MCU or the joystick mapping. The fix tracks which codes the initial keydown consumed (Amiga-mapped key or joystick control) in a set and calls
preventDefault()on their repeats without forwarding them.keyupclears the entry, which also keeps the set from going stale when a hold spans a focus loss.Testing
node --checkontry.jskeysjoystick mode - the page no longer scrolls and the guest still sees a single key-down per press.