emscripten: Make an attempt at correct keyboard scancode/keycodes.
This uses a newer browser API to get physical scancodes, but still uses the (deprecated) event field that we were already using for scancodes, but for keycodes instead now, which appears to be more accurate. Since keyboard layout isn't (generally) available to web apps, this adds an internal interface to send key events with both scancode and keycode to SDL's internals, instead of sending just scancodes and expecting SDL to use its own keymap to generate keycodes. Future work in this area would be to use the keyboard layout APIs on browsers that support them, which would allow us to use SDL's usual keymap code and not rely on a deprecated browser API, but until we get there, this patch gives significantly more correct results than we would have before. Fixes #2098.
This commit is contained in:
parent
0ddec7e421
commit
9221548114
3 changed files with 578 additions and 324 deletions
|
@ -800,12 +800,11 @@ SDL_SetKeyboardFocus(SDL_Window * window)
|
|||
}
|
||||
|
||||
static int
|
||||
SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
|
||||
SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
|
||||
{
|
||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||
int posted;
|
||||
SDL_Keymod modifier;
|
||||
SDL_Keycode keycode;
|
||||
Uint32 type;
|
||||
Uint8 repeat = SDL_FALSE;
|
||||
|
||||
|
@ -851,7 +850,9 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
|
|||
/* Update internal keyboard state */
|
||||
keyboard->keystate[scancode] = state;
|
||||
|
||||
keycode = keyboard->keymap[scancode];
|
||||
if (keycode == SDLK_UNKNOWN) {
|
||||
keycode = keyboard->keymap[scancode];
|
||||
}
|
||||
|
||||
if (source == KEYBOARD_AUTORELEASE) {
|
||||
keyboard->autorelease_pending = SDL_TRUE;
|
||||
|
@ -971,13 +972,19 @@ SDL_SendKeyboardUnicodeKey(Uint32 ch)
|
|||
int
|
||||
SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
|
||||
{
|
||||
return SDL_SendKeyboardKeyInternal(KEYBOARD_HARDWARE, state, scancode);
|
||||
return SDL_SendKeyboardKeyInternal(KEYBOARD_HARDWARE, state, scancode, SDLK_UNKNOWN);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendKeyboardKeyComplete(Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
|
||||
{
|
||||
return SDL_SendKeyboardKeyInternal(KEYBOARD_HARDWARE, state, scancode, keycode);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendKeyboardKeyAutoRelease(SDL_Scancode scancode)
|
||||
{
|
||||
return SDL_SendKeyboardKeyInternal(KEYBOARD_AUTORELEASE, SDL_PRESSED, scancode);
|
||||
return SDL_SendKeyboardKeyInternal(KEYBOARD_AUTORELEASE, SDL_PRESSED, scancode, SDLK_UNKNOWN);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -989,7 +996,7 @@ SDL_ReleaseAutoReleaseKeys(void)
|
|||
if (keyboard->autorelease_pending) {
|
||||
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
|
||||
if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
|
||||
SDL_SendKeyboardKeyInternal(KEYBOARD_AUTORELEASE, SDL_RELEASED, scancode);
|
||||
SDL_SendKeyboardKeyInternal(KEYBOARD_AUTORELEASE, SDL_RELEASED, scancode, SDLK_UNKNOWN);
|
||||
}
|
||||
}
|
||||
keyboard->autorelease_pending = SDL_FALSE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue