From 6f804758f1be79a567d1122501c1a654f31ce7c9 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Fri, 10 Jun 2022 19:53:03 -0700 Subject: [PATCH] Fix preact apple keys --- js/apple2io.ts | 4 ++-- js/components/Keyboard.tsx | 9 +++++---- js/components/css/Keyboard.module.css | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/js/apple2io.ts b/js/apple2io.ts index a50d332..eda59a5 100644 --- a/js/apple2io.ts +++ b/js/apple2io.ts @@ -421,8 +421,8 @@ export default class Apple2IO implements MemoryPages, Restorable this._keyDown = false; } - buttonDown(b: button) { - this._button[b] = true; + buttonDown(b: button, state = true) { + this._button[b] = state; } buttonUp(b: button) { diff --git a/js/components/Keyboard.tsx b/js/components/Keyboard.tsx index 50af7d6..eacee4e 100644 --- a/js/components/Keyboard.tsx +++ b/js/components/Keyboard.tsx @@ -145,9 +145,10 @@ export const Keyboard = ({ apple2, e }: KeyboardProps) => { const toggleActive = (key: string) => { if (!active.includes(key)) { setActive([...active, key]); - } else { - setActive(active.filter(x => x !== key)); + return true; } + setActive(active.filter(x => x !== key)); + return false; }; const io = apple2.getIO(); @@ -171,11 +172,11 @@ export const Keyboard = ({ apple2, e }: KeyboardProps) => { apple2.reset(); break; case 'OPEN_APPLE': - io.ioSwitch(0, io.ioSwitch(0) ? 0 : 1); + io.buttonDown(0, toggleActive(key)); toggleActive(key); break; case 'CLOSED_APPLE': - io.ioSwitch(1, io.ioSwitch(1) ? 0 : 1); + io.buttonDown(1, toggleActive(key)); toggleActive(key); break; default: diff --git a/js/components/css/Keyboard.module.css b/js/components/css/Keyboard.module.css index 377fbff..c1cabff 100644 --- a/js/components/css/Keyboard.module.css +++ b/js/components/css/Keyboard.module.css @@ -1,5 +1,6 @@ .keyboard { margin-left: 15px; + user-select: none; } :global(.apple2e) .keyboard {