Skip to content

web: suppress the browser default on held-key auto-repeats#262

Merged
LinuxJedi merged 2 commits into
mainfrom
fix/web-key-repeat-scroll
Jul 23, 2026
Merged

web: suppress the browser default on held-key auto-repeats#262
LinuxJedi merged 2 commits into
mainfrom
fix/web-key-repeat-scroll

Conversation

@LinuxJedi

Copy link
Copy Markdown
Collaborator

Summary

Holding a cursor key in a browser session scrolled the page under the game. The keydown handler in try.js returned early on e.repeat before reaching preventDefault(), 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. keyup clears the entry, which also keeps the set from going stale when a hold spans a focus loss.

Testing

  • node --check on try.js
  • Manual: hold ArrowUp/ArrowDown in a scrollable page shell while a game is running, in both keyboard mode and the keys joystick mode - the page no longer scrolls and the guest still sees a single key-down per press.

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.
Copilot AI review requested due to automatic review settings July 23, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 consumedKeys tracking so keydown auto-repeat can be suppressed in the browser without re-forwarding repeats into the emulator.
  • Update keyup handling to clear consumed key tracking and suppress defaults when appropriate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/copperline-web/www/try.js Outdated
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.
@LinuxJedi
LinuxJedi merged commit 99e6e66 into main Jul 23, 2026
11 checks passed
@LinuxJedi
LinuxJedi deleted the fix/web-key-repeat-scroll branch July 23, 2026 09:36
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