From d1858eb124293ace5783a5e1a6788df7c57c02a8 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Fri, 4 Nov 2022 12:33:45 -0400 Subject: [PATCH] events: Add a helper function to get the default keycode for a scancode Add a helper function to get the keycode for a scancode from the default lookup table. Unlike SDL_GetKeyFromScancode(), this is not affected by the set keymap. --- src/events/SDL_keyboard.c | 11 +++++++++++ src/events/SDL_keyboard_c.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 7dc0fb9b2..30ec14c24 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -1137,6 +1137,17 @@ SDL_GetKeyFromScancode(SDL_Scancode scancode) return keyboard->keymap[scancode]; } +SDL_Keycode +SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode) +{ + if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { + SDL_InvalidParamError("scancode"); + return 0; + } + + return SDL_default_keymap[scancode]; +} + SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key) { diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h index db9703aaf..3ace4af64 100644 --- a/src/events/SDL_keyboard_c.h +++ b/src/events/SDL_keyboard_c.h @@ -32,6 +32,9 @@ extern int SDL_KeyboardInit(void); /* Get the default keymap */ extern void SDL_GetDefaultKeymap(SDL_Keycode * keymap); +/* Get the default key code for a scancode */ +extern SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode); + /* Set the mapping of scancode to key codes */ extern void SDL_SetKeymap(int start, const SDL_Keycode * keys, int length, SDL_bool send_event);