ref: 322a439d801c91cf30a208cff499b33f4a5a2123
parent: c1059c07fbb77f3f697b305aa55cdcd4361faf5c
author: Ben Harris <[email protected]>
date: Mon Oct 24 18:07:12 EDT 2022
js: Use KeyboardEvent.keyCode and .char only as fallbacks KeyboardEvent.keyCode is a platform-dependent mess. KeyboardEvent.char is better-defined, but in my browser it's always null. KeyboardEvent.key is the right thing to use when we want to know the semantics of a key. This commit just re-organises the big "else if" chain in key() so that all the tests on "key" come first. That way at least if key and keyCode disagree, we'll use the more trustworthy one.
--- a/emcc.c
+++ b/emcc.c
@@ -267,20 +267,19 @@
{
int keyevent = -1;
- if (!strnullcmp(key, "Backspace") || !strnullcmp(key, "Del") ||
- keycode == 8 || keycode == 46)
+ if (!strnullcmp(key, "Backspace") || !strnullcmp(key, "Del"))
keyevent = 127; /* Backspace / Delete */
- else if (!strnullcmp(key, "Enter") || keycode == 13)
+ else if (!strnullcmp(key, "Enter"))
keyevent = 13; /* return */
- else if (!strnullcmp(key, "Left") || keycode == 37)
+ else if (!strnullcmp(key, "Left"))
keyevent = CURSOR_LEFT;
- else if (!strnullcmp(key, "Up") || keycode == 38)
+ else if (!strnullcmp(key, "Up"))
keyevent = CURSOR_UP;
- else if (!strnullcmp(key, "Right") || keycode == 39)
+ else if (!strnullcmp(key, "Right"))
keyevent = CURSOR_RIGHT;
- else if (!strnullcmp(key, "Down") || keycode == 40)
+ else if (!strnullcmp(key, "Down"))
keyevent = CURSOR_DOWN;
- else if (!strnullcmp(key, "End") || keycode == 35)
+ else if (!strnullcmp(key, "End"))
/*
* We interpret Home, End, PgUp and PgDn as numeric keypad
* controls regardless of whether they're the ones on the
@@ -290,11 +289,31 @@
* puzzles like Cube and Inertia.
*/
keyevent = MOD_NUM_KEYPAD | '1';
- else if (!strnullcmp(key, "PageDown") || keycode==34)
+ else if (!strnullcmp(key, "PageDown"))
keyevent = MOD_NUM_KEYPAD | '3';
- else if (!strnullcmp(key, "Home") || keycode==36)
+ else if (!strnullcmp(key, "Home"))
keyevent = MOD_NUM_KEYPAD | '7';
- else if (!strnullcmp(key, "PageUp") || keycode==33)
+ else if (!strnullcmp(key, "PageUp"))
+ keyevent = MOD_NUM_KEYPAD | '9';
+ else if (keycode == 8 || keycode == 46)
+ keyevent = 127; /* Backspace / Delete */
+ else if (keycode == 13)
+ keyevent = 13; /* return */
+ else if (keycode == 37)
+ keyevent = CURSOR_LEFT;
+ else if (keycode == 38)
+ keyevent = CURSOR_UP;
+ else if (keycode == 39)
+ keyevent = CURSOR_RIGHT;
+ else if (keycode == 40)
+ keyevent = CURSOR_DOWN;
+ else if (keycode == 35)
+ keyevent = MOD_NUM_KEYPAD | '1';
+ else if (keycode == 34)
+ keyevent = MOD_NUM_KEYPAD | '3';
+ else if (keycode == 36)
+ keyevent = MOD_NUM_KEYPAD | '7';
+ else if (keycode == 33)
keyevent = MOD_NUM_KEYPAD | '9';
else if (shift && ctrl && (keycode & 0x1F) == 26)
keyevent = UI_REDO;