-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c087808
commit a1df7cc
Showing
11 changed files
with
170 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Infocom Frotz interface hacks | ||
|
||
const canvas_elem = document.getElementById('canvas') | ||
const textinput_elem = document.getElementById('textinput') | ||
|
||
// Mobile input event handlers | ||
canvas_elem.addEventListener('touchstart', ev => { | ||
textinput_elem.focus() | ||
}) | ||
textinput_elem.addEventListener('input', ev => { | ||
const char = ev.data | ||
if (char) { | ||
const char_keycode = char.codePointAt(0) | ||
const upper_key = char.toUpperCase() | ||
const upper_keycode = upper_key.codePointAt(0) | ||
const down_up_options = { | ||
code: 'Key' + upper_key, | ||
key: char, | ||
keyCode: upper_keycode, | ||
which: upper_keycode, | ||
} | ||
window.dispatchEvent(new KeyboardEvent('keydown', down_up_options)) | ||
window.dispatchEvent(new KeyboardEvent('keypress', { | ||
charCode: char_keycode, | ||
code: 'Key' + upper_key, | ||
key: char, | ||
keyCode: char_keycode, | ||
which: char_keycode, | ||
})) | ||
window.dispatchEvent(new KeyboardEvent('keyup', down_up_options)) | ||
} | ||
|
||
// To fully reset we have to clear the value then blur and refocus, otherwise Android will keep trying to do its IME magic, which we don't want. | ||
textinput_elem.value = '' | ||
textinput_elem.blur() | ||
textinput_elem.focus() | ||
|
||
ev.preventDefault() | ||
ev.stopPropagation() | ||
}) | ||
textinput_elem.addEventListener('keydown', ev => { | ||
if (ev.which === 8) { | ||
const options = { | ||
code: 'Backspace', | ||
key: 'Backspace', | ||
keyCode: 8, | ||
which: 8, | ||
} | ||
window.dispatchEvent(new KeyboardEvent('keydown', options)) | ||
window.dispatchEvent(new KeyboardEvent('keyup', options)) | ||
ev.preventDefault() | ||
ev.stopPropagation() | ||
} | ||
if (ev.which === 13) { | ||
const options = { | ||
charCode: 13, | ||
code: 'Enter', | ||
key: 'Enter', | ||
keyCode: 13, | ||
which: 13, | ||
} | ||
window.dispatchEvent(new KeyboardEvent('keydown', options)) | ||
window.dispatchEvent(new KeyboardEvent('keypress', options)) | ||
window.dispatchEvent(new KeyboardEvent('keyup', options)) | ||
ev.preventDefault() | ||
ev.stopPropagation() | ||
} | ||
if (ev.which === 229) { | ||
ev.preventDefault() | ||
ev.stopPropagation() | ||
} | ||
}) | ||
textinput_elem.addEventListener('keyup', ev => { | ||
if (ev.which === 8 || ev.which === 13 || ev.which === 229) { | ||
ev.preventDefault() | ||
ev.stopPropagation() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters