diff options
-rw-r--r-- | projects/chip8emu/index.html | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/projects/chip8emu/index.html b/projects/chip8emu/index.html index 9f34340..212d584 100644 --- a/projects/chip8emu/index.html +++ b/projects/chip8emu/index.html @@ -13,7 +13,26 @@ layout: project <progress value="0" max="100" id="progress" hidden=0></progress> <canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex=0></canvas> -<button class="chip8-button">Q</button> +<button class="chip8-button" id="1">1</button> +<button class="chip8-button" id="2">2</button> +<button class="chip8-button" id="3">3</button> +<button class="chip8-button" id="4">4</button> +<br> +<button class="chip8-button" id="q">Q</button> +<button class="chip8-button" id="w">W</button> +<button class="chip8-button" id="e">E</button> +<button class="chip8-button" id="r">R</button> +<br> +<button class="chip8-button" id="a">A</button> +<button class="chip8-button" id="s">S</button> +<button class="chip8-button" id="d">D</button> +<button class="chip8-button" id="f">F</button> +<br> +<button class="chip8-button" id="z">Z</button> +<button class="chip8-button" id="x">X</button> +<button class="chip8-button" id="c">C</button> +<button class="chip8-button" id="v">V</button> +<br> <script type="text/javascript" src="module.js"></script> <script async type="text/javascript" src="chip8emu.js"></script> @@ -24,4 +43,37 @@ layout: project c.focus(); c.dispatchEvent(new KeyboardEvent(eventType, {'keyCode': keyCode})); } + + const KEYS = { + '1': 49, + '2': 50, + '3': 51, + '4': 52, + 'q': 81, + 'w': 87, + 'e': 69, + 'r': 82, + 'a': 65, + 's': 83, + 'd': 68, + 'f': 70, + 'z': 90, + 'x': 88, + 'c': 67, + 'v': 86 + } + + async function tap(e) { + sendKey(81, 'keydown'); + + await new Promise(r => setTimeout(r, 10)); + + sendKey(81, 'keyup'); + } + + Object.keys(KEYS).forEach(id => { + console.log(id); + const element = document.getElementById(id); + element.addEventListener('click', tap); + }); </script> |