Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions crates/copperline-web/www/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,32 @@ function updatePadStatus(releasedPort1) {

// --- keyboard ------------------------------------------------------------

// Auto-repeat keydowns must not reach the emulator (the Amiga keyboard
// sends one down code; the guest OS does its own repeat), but the browser
// default still has to be suppressed on every repeat or holding a cursor
// key scrolls the page. Track which codes the first keydown consumed.
const consumedKeys = new Set();
window.addEventListener('keydown', (e) => {
if (!emu || !running || e.repeat) return;
if (joystickKey(e.code, true) || emu.key_event(e.code, true)) e.preventDefault();
if (!emu || !running) return;
if (e.repeat) {
if (consumedKeys.has(e.code)) e.preventDefault();
return;
}
if (joystickKey(e.code, true) || emu.key_event(e.code, true)) {
consumedKeys.add(e.code);
e.preventDefault();
} else {
consumedKeys.delete(e.code);
}
});
window.addEventListener('keyup', (e) => {
// Delete before the running check: a hold that spans an emulator stop
// or a focus loss must not leave a stale entry behind.
const consumed = consumedKeys.delete(e.code);
if (!emu || !running) return;
if (joystickKey(e.code, false) || emu.key_event(e.code, false)) e.preventDefault();
if (joystickKey(e.code, false) || emu.key_event(e.code, false) || consumed) {
e.preventDefault();
}
});

// --- mouse ---------------------------------------------------------------
Expand Down
Loading