aboutsummaryrefslogtreecommitdiff
path: root/emcc.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-24 23:06:12 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-10-24 23:13:33 +0100
commit768ef770a351ee1528e6e7923d3b3b00654401cb (patch)
tree89ca8fe8024726c74ca73eb9dc05de4f991b7e11 /emcc.c
parent0db5fb525bb58056caf9303d2ac159fc51c04e04 (diff)
downloadpuzzles-768ef770a351ee1528e6e7923d3b3b00654401cb.zip
puzzles-768ef770a351ee1528e6e7923d3b3b00654401cb.tar.gz
puzzles-768ef770a351ee1528e6e7923d3b3b00654401cb.tar.bz2
puzzles-768ef770a351ee1528e6e7923d3b3b00654401cb.tar.xz
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.
Diffstat (limited to 'emcc.c')
-rw-r--r--emcc.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/emcc.c b/emcc.c
index 33f7608..6c16248 100644
--- a/emcc.c
+++ b/emcc.c
@@ -262,9 +262,14 @@ void mousemove(int x, int y, int buttons)
/*
* Keyboard handler called from JS.
*/
-void key(int keycode, const char *key, const char *chr,
+void key(int keycode, const char *key, const char *chr, int location,
bool shift, bool ctrl)
{
+ /* Key location constants from JavaScript. */
+ #define DOM_KEY_LOCATION_STANDARD 0
+ #define DOM_KEY_LOCATION_LEFT 1
+ #define DOM_KEY_LOCATION_RIGHT 2
+ #define DOM_KEY_LOCATION_NUMPAD 3
int keyevent = -1;
if (!strnullcmp(key, "Backspace") || !strnullcmp(key, "Delete") ||
@@ -296,6 +301,9 @@ void key(int keycode, const char *key, const char *chr,
keyevent = MOD_NUM_KEYPAD | '7';
else if (!strnullcmp(key, "PageUp"))
keyevent = MOD_NUM_KEYPAD | '9';
+ else if (key && (unsigned char)key[0] < 0x80 && key[1] == '\0')
+ /* Key generating a single ASCII character. */
+ keyevent = key[0];
else if (keycode == 8 || keycode == 46)
keyevent = 127; /* Backspace / Delete */
else if (keycode == 13)
@@ -340,6 +348,10 @@ void key(int keycode, const char *key, const char *chr,
keyevent &= 0x1F;
}
+ if ('0' <= keyevent && keyevent <= '9' &&
+ location == DOM_KEY_LOCATION_NUMPAD)
+ keyevent |= MOD_NUM_KEYPAD;
+
midend_process_key(me, 0, 0, keyevent);
update_undo_redo();
}