mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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.
This commit is contained in:
7
emcc.c
7
emcc.c
@ -260,9 +260,10 @@ void mousemove(int x, int y, int buttons)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keyboard handler called from JS.
|
* Keyboard handler called from JS. Returns true if the key was
|
||||||
|
* handled and hence the keydown event should be cancelled.
|
||||||
*/
|
*/
|
||||||
void key(int keycode, const char *key, const char *chr, int location,
|
bool key(int keycode, const char *key, const char *chr, int location,
|
||||||
bool shift, bool ctrl)
|
bool shift, bool ctrl)
|
||||||
{
|
{
|
||||||
/* Key location constants from JavaScript. */
|
/* Key location constants from JavaScript. */
|
||||||
@ -366,7 +367,9 @@ void key(int keycode, const char *key, const char *chr, int location,
|
|||||||
|
|
||||||
midend_process_key(me, 0, 0, keyevent);
|
midend_process_key(me, 0, 0, keyevent);
|
||||||
update_undo_redo();
|
update_undo_redo();
|
||||||
|
return true; /* We've probably handled the event. */
|
||||||
}
|
}
|
||||||
|
return false; /* Event not handled, because we don't even recognise it. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
12
emccpre.js
12
emccpre.js
@ -305,16 +305,16 @@ function initPuzzle() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Set up keyboard handlers. We call event.preventDefault()
|
// Set up keyboard handlers. We call event.preventDefault()
|
||||||
// in the keydown handler. This means that
|
// in the keydown handler if it looks like we might have
|
||||||
// while the canvas itself has focus, _all_ keypresses go only to
|
// done something with the key. This means that users
|
||||||
// the puzzle - so users of this puzzle collection in other media
|
// of this puzzle collection in other media
|
||||||
// can indulge their instinct to press ^R for redo, for example,
|
// can indulge their instinct to press ^R for redo, for example,
|
||||||
// without accidentally reloading the page.
|
// without accidentally reloading the page.
|
||||||
key = Module.cwrap('key', 'void', ['number', 'string', 'string',
|
key = Module.cwrap('key', 'boolean', ['number', 'string', 'string',
|
||||||
'number', 'number', 'number']);
|
'number', 'number', 'number']);
|
||||||
onscreen_canvas.onkeydown = function(event) {
|
onscreen_canvas.onkeydown = function(event) {
|
||||||
key(event.keyCode, event.key, event.char, event.location,
|
if (key(event.keyCode, event.key, event.char, event.location,
|
||||||
event.shiftKey ? 1 : 0, event.ctrlKey ? 1 : 0);
|
event.shiftKey ? 1 : 0, event.ctrlKey ? 1 : 0))
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user