js: Use KeyboardEvent.key for ASCII keystrokes

This requires passing in KeyboardEvent.location from JavaScript so
that we can detect the numeric keypad properly.  Out of caution we
currently only set MOD_NUM_KEYPAD on numbers, like we always have,
but we have enough information to set it on arrow keys, Enter, "+",
etc.

This finally gets '/' and '\' working in Slant again.
This commit is contained in:
Ben Harris
2022-10-24 23:06:12 +01:00
parent 0db5fb525b
commit 768ef770a3
2 changed files with 16 additions and 4 deletions

View File

@ -311,10 +311,10 @@ function initPuzzle() {
// the puzzle - so users of this puzzle collection in other media
// can indulge their instinct to press ^R for redo, for example,
// without accidentally reloading the page.
key = Module.cwrap('key', 'void', ['number', 'string',
'string', 'number', 'number']);
key = Module.cwrap('key', 'void', ['number', 'string', 'string',
'number', 'number', 'number']);
onscreen_canvas.onkeydown = function(event) {
key(event.keyCode, event.key, event.char,
key(event.keyCode, event.key, event.char, event.location,
event.shiftKey ? 1 : 0, event.ctrlKey ? 1 : 0);
event.preventDefault();
};