aboutsummaryrefslogtreecommitdiff
path: root/emccpre.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-25 20:38:37 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-10-25 20:38:37 +0100
commit5fae5ca0db6a263d385c05cb6cfef5e3e3b18630 (patch)
treef5ceb3c2502bc0b048269ad75e2a7028fad34b66 /emccpre.js
parente6faebeb9a1856c9ea7140eb650b48ada0adc923 (diff)
downloadpuzzles-5fae5ca0db6a263d385c05cb6cfef5e3e3b18630.zip
puzzles-5fae5ca0db6a263d385c05cb6cfef5e3e3b18630.tar.gz
puzzles-5fae5ca0db6a263d385c05cb6cfef5e3e3b18630.tar.bz2
puzzles-5fae5ca0db6a263d385c05cb6cfef5e3e3b18630.tar.xz
js: Be more subtle about cancelling keydown events
Now we only cancel a keydown event if the C keyboard handler recognises the key and passes it on to the midend. This doesn't necessarily mean that the midend has actually done anything with it, of course. Still, this is enough to allow F12 to open the developer tools even when the input focus is on the puzzle. It also allows for tabbing out of the puzzle into the links below it.
Diffstat (limited to 'emccpre.js')
-rw-r--r--emccpre.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/emccpre.js b/emccpre.js
index ee06019..37e5829 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -305,17 +305,17 @@ function initPuzzle() {
};
// Set up keyboard handlers. We call event.preventDefault()
- // in the keydown handler. This means that
- // while the canvas itself has focus, _all_ keypresses go only to
- // the puzzle - so users of this puzzle collection in other media
+ // in the keydown handler if it looks like we might have
+ // done something with the key. This means that 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', 'number']);
+ key = Module.cwrap('key', 'boolean', ['number', 'string', 'string',
+ 'number', 'number', 'number']);
onscreen_canvas.onkeydown = function(event) {
- key(event.keyCode, event.key, event.char, event.location,
- event.shiftKey ? 1 : 0, event.ctrlKey ? 1 : 0);
- event.preventDefault();
+ if (key(event.keyCode, event.key, event.char, event.location,
+ event.shiftKey ? 1 : 0, event.ctrlKey ? 1 : 0))
+ event.preventDefault();
};
// command() is a C function called to pass back events which