From a6a88772818c91a17c0646f841782ca5ab84f328 Mon Sep 17 00:00:00 2001 From: Dannii Willis Date: Sat, 18 May 2024 11:29:48 +1000 Subject: [PATCH] Working on mobile input --- arthur.html | 3 ++- journey.html | 3 ++- sfrotz.js | 30 ++++++++++++++++++++++++++++-- shogun.html | 3 ++- styles.css | 5 +++++ zorkzero.html | 3 ++- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/arthur.html b/arthur.html index e6a9467..2099da8 100644 --- a/arthur.html +++ b/arthur.html @@ -7,8 +7,9 @@ -

Arthur: The Quest for Excalibur

+

Arthur

+

Other games on Infocom Frotz

diff --git a/journey.html b/journey.html index 5c81ad4..d5be6cb 100644 --- a/journey.html +++ b/journey.html @@ -7,8 +7,9 @@ -

Journey: The Quest Begins

+

Journey

+

Other games on Infocom Frotz

diff --git a/sfrotz.js b/sfrotz.js index d8dbf1a..a433cde 100644 --- a/sfrotz.js +++ b/sfrotz.js @@ -32,6 +32,7 @@ if (Module['ENVIRONMENT']) { // Infocom Frotz Emscripten preamble const files = window.files +const textinput_elem = document.getElementById('textinput') Module.arguments = ['/' + files[0], '/' + files[1]] Module.canvas = document.getElementById('canvas') @@ -8761,8 +8762,33 @@ var ASM_CONSTS = { }; return JSEvents.registerOrRemoveHandler(eventHandler); }; - var _emscripten_set_keydown_callback_on_thread = (target, userData, useCapture, callbackfunc, targetThread) => - registerKeyEventCallback(target, userData, useCapture, callbackfunc, 2, "keydown", targetThread); + var _emscripten_set_keydown_callback_on_thread = function emscripten_set_keydown_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {console.log('emscripten_set_keydown_callback_on_thread', target, userData, useCapture, callbackfunc) + registerKeyEventCallback(target, userData, useCapture, callbackfunc, 2, "keydown", targetThread) + + // Input handling for mobile + // Process input events + textinput_elem.addEventListener('input', ev => { + console.log('input event', ev) + const char = ev.data + textinput_elem.value = '' + if (char) { + const new_event = new KeyboardEvent('keydown', {key: char}) + document.dispatchEvent(new_event) + } + // Even though we have reset and emptied the input, Android acts as though it still has spaces within it, and won't send backspace keydown events until the phantom spaces have all been deleted. Refocusing seems to fix it. + if (char === ' ') { + textinput_elem.blur() + textinput_elem.focus() + } + }) + // Ignore keydown events which return 229 - which is most events on mobile Chrome + textinput_elem.addEventListener('keydown', ev => { + console.log('keydown event', ev) + if (ev.which === 229) { + ev.stopPropagation() + } + }) + }; var _emscripten_set_keypress_callback_on_thread = (target, userData, useCapture, callbackfunc, targetThread) => registerKeyEventCallback(target, userData, useCapture, callbackfunc, 1, "keypress", targetThread); diff --git a/shogun.html b/shogun.html index d97104e..7d2a48a 100644 --- a/shogun.html +++ b/shogun.html @@ -7,8 +7,9 @@ -

James Clavell's Shōgun

+

Shōgun

+

Other games on Infocom Frotz

diff --git a/styles.css b/styles.css index 3c67b31..d4ca8d4 100644 --- a/styles.css +++ b/styles.css @@ -25,4 +25,9 @@ a { #games h2 img { display: block; margin: 0 auto; +} + +#textinput { + position: absolute; + left: -10000px; } \ No newline at end of file diff --git a/zorkzero.html b/zorkzero.html index 09c4e55..7d6968c 100644 --- a/zorkzero.html +++ b/zorkzero.html @@ -7,8 +7,9 @@ -

Zork Zero: The Revenge of Megaboz

+

Zork Zero

+

Other games on Infocom Frotz