Skip to content

Commit

Permalink
Fixed detection of function keys on Emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 15, 2025
1 parent 23410de commit 67382e9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/video/emscripten/SDL_emscriptenevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ static EM_BOOL Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent
return preventDefault;
}

static bool IsFunctionKey(SDL_Scancode scancode)
{
if (scancode >= SDL_SCANCODE_F1 && scancode <= SDL_SCANCODE_F12) {
return true;
}
if (scancode >= SDL_SCANCODE_F13 && scancode <= SDL_SCANCODE_F24) {
return true;
}
return false;
}

/* This is a great tool to see web keyboard events live:
* https://w3c.github.io/uievents/tools/key-event-viewer.html
*/
Expand Down Expand Up @@ -557,7 +568,7 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent
(scancode == SDL_SCANCODE_UP) ||
(scancode == SDL_SCANCODE_RIGHT) ||
(scancode == SDL_SCANCODE_DOWN) ||
((scancode >= SDL_SCANCODE_F1) && (scancode <= SDL_SCANCODE_F15)) ||
IsFunctionKey(scancode) ||
keyEvent->ctrlKey) {
is_nav_key = true;
}
Expand Down

0 comments on commit 67382e9

Please sign in to comment.