From 542a3663defbda3eeaad7aea27bb62b80c555319 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 28 May 2024 19:47:17 -0700 Subject: [PATCH] Added SDL_GetDefaultKeyFromScancode() to the public API This is useful when getting the English name of a key for a non-Latin keyboard layout, for example. --- include/SDL3/SDL_keyboard.h | 15 +++++++++++++++ src/dynapi/SDL_dynapi.sym | 1 + src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 1 + 4 files changed, 18 insertions(+) diff --git a/include/SDL3/SDL_keyboard.h b/include/SDL3/SDL_keyboard.h index 731cc60597..b23d37b297 100644 --- a/include/SDL3/SDL_keyboard.h +++ b/include/SDL3/SDL_keyboard.h @@ -202,6 +202,21 @@ extern SDL_DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void); */ extern SDL_DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate); +/** + * Get the key code corresponding to the given scancode according to a default en_US keyboard layout. + * + * See SDL_Keycode for details. + * + * \param scancode the desired SDL_Scancode to query + * \returns the SDL_Keycode that corresponds to the given SDL_Scancode. + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_GetKeyName + * \sa SDL_GetScancodeFromKey + */ +extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode); + /** * Get the key code corresponding to the given scancode according to the * current keyboard layout. diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 53de3ff3ef..89d284c92f 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -209,6 +209,7 @@ SDL3_0.0.0 { SDL_GetDaysInMonth; SDL_GetDefaultAssertionHandler; SDL_GetDefaultCursor; + SDL_GetDefaultKeyFromScancode; SDL_GetDesktopDisplayMode; SDL_GetDisplayBounds; SDL_GetDisplayContentScale; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index f64025b4ea..45d91c1ac6 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -234,6 +234,7 @@ #define SDL_GetDaysInMonth SDL_GetDaysInMonth_REAL #define SDL_GetDefaultAssertionHandler SDL_GetDefaultAssertionHandler_REAL #define SDL_GetDefaultCursor SDL_GetDefaultCursor_REAL +#define SDL_GetDefaultKeyFromScancode SDL_GetDefaultKeyFromScancode_REAL #define SDL_GetDesktopDisplayMode SDL_GetDesktopDisplayMode_REAL #define SDL_GetDisplayBounds SDL_GetDisplayBounds_REAL #define SDL_GetDisplayContentScale SDL_GetDisplayContentScale_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 1cbcb92d15..e77bea0986 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -254,6 +254,7 @@ SDL_DYNAPI_PROC(int,SDL_GetDayOfYear,(int a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetDaysInMonth,(int a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetDefaultAssertionHandler,(void),(),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetDefaultCursor,(void),(),return) +SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetDefaultKeyFromScancode,(SDL_Scancode a),(a),return) SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetDesktopDisplayMode,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) SDL_DYNAPI_PROC(float,SDL_GetDisplayContentScale,(SDL_DisplayID a),(a),return)