Added the ability to query the keymap for keycodes based on modifier state

This commit is contained in:
Sam Lantinga
2024-06-19 15:00:12 -07:00
parent ef9bd8b609
commit 679e4471ed
34 changed files with 1388 additions and 1409 deletions

View File

@@ -316,8 +316,7 @@ typedef struct SDL_KeyboardEvent
/**
* Keyboard text editing event structure (event.edit.*)
*
* The `text` is owned by SDL and should be copied if the application wants to
* hold onto it beyond the scope of handling this event.
* The text string follows the SDL_GetStringRule.
*
* \since This struct is available since SDL 3.0.0.
*/
@@ -335,8 +334,7 @@ typedef struct SDL_TextEditingEvent
/**
* Keyboard text input event structure (event.text.*)
*
* The `text` is owned by SDL and should be copied if the application wants to
* hold onto it beyond the scope of handling this event.
* The text string follows the SDL_GetStringRule.
*
* This event will never be delivered unless text input is enabled by calling
* SDL_StartTextInput(). Text input is disabled by default!
@@ -733,7 +731,7 @@ typedef struct SDL_PenButtonEvent
* An event used to drop text or request a file open by the system
* (event.drop.*)
*
* The `source` and `data` are owned by SDL and should be copied if the application wants to hold onto them beyond the scope of handling this event.
* The source and data strings follow the SDL_GetStringRule.
*
* \since This struct is available since SDL 3.0.0.
*/

View File

@@ -211,6 +211,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
* See SDL_Keycode for details.
*
* \param scancode the desired SDL_Scancode to query.
* \param modstate the modifier state to use when translating the scancode to a keycode.
* \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
*
* \since This function is available since SDL 3.0.0.
@@ -218,7 +219,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
* \sa SDL_GetKeyName
* \sa SDL_GetScancodeFromKey
*/
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode);
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate);
/**
* Get the key code corresponding to the given scancode according to the
@@ -227,36 +228,68 @@ extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetDefaultKeyFromScancode(SDL_Scanco
* See SDL_Keycode for details.
*
* \param scancode the desired SDL_Scancode to query.
* \param modstate the modifier state to use when translating the scancode to a keycode.
* \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetDefaultKeyFromScancode
* \sa SDL_GetKeyName
* \sa SDL_GetScancodeFromKey
*/
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate);
/**
* Get the scancode corresponding to the given key code according to a default en_US keyboard layout.
*
* Note that there may be multiple scancode+modifier states that can generate this keycode, this will just return the first one found.
*
* \param key the desired SDL_Keycode to query.
* \param modstate a pointer to the modifier state that would be used when the scancode generates this key, may be NULL.
* \returns the SDL_Scancode that corresponds to the given SDL_Keycode.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetScancodeFromKey
* \sa SDL_GetScancodeName
*/
extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetDefaultScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate);
/**
* Get the scancode corresponding to the given key code according to the
* current keyboard layout.
*
* See SDL_Scancode for details.
* Note that there may be multiple scancode+modifier states that can generate this keycode, this will just return the first one found.
*
* \param key the desired SDL_Keycode to query.
* \param modstate a pointer to the modifier state that would be used when the scancode generates this key, may be NULL.
* \returns the SDL_Scancode that corresponds to the given SDL_Keycode.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetDefaultScancodeFromKey
* \sa SDL_GetKeyFromScancode
* \sa SDL_GetScancodeName
*/
extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate);
/**
* Set a human-readable name for a scancode.
*
* \param scancode the desired SDL_Scancode.
* \param name the name to use for the scancode, encoded as UTF-8. The string is not copied, so the pointer given to this function must stay valid while SDL is being used.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetScancodeName
*/
extern SDL_DECLSPEC int SDLCALL SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
/**
* Get a human-readable name for a scancode.
*
* See SDL_Scancode for details.
*
* The returned string follows the SDL_GetStringRule.
*
* **Warning**: The returned name is by design not stable across platforms,
@@ -276,6 +309,7 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key)
*
* \sa SDL_GetScancodeFromKey
* \sa SDL_GetScancodeFromName
* \sa SDL_SetScancodeName
*/
extern SDL_DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
@@ -297,8 +331,6 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
/**
* Get a human-readable name for a key.
*
* See SDL_Scancode and SDL_Keycode for details.
*
* The returned string follows the SDL_GetStringRule.
*
* \param key the desired SDL_Keycode to query.

View File

@@ -88,6 +88,32 @@ typedef Uint32 SDL_Keycode;
#define SDLK_GREATER '>'
#define SDLK_QUESTION '?'
#define SDLK_AT '@'
#define SDLK_A 'A'
#define SDLK_B 'B'
#define SDLK_C 'C'
#define SDLK_D 'D'
#define SDLK_E 'E'
#define SDLK_F 'F'
#define SDLK_G 'G'
#define SDLK_H 'H'
#define SDLK_I 'I'
#define SDLK_J 'J'
#define SDLK_K 'K'
#define SDLK_L 'L'
#define SDLK_M 'M'
#define SDLK_N 'N'
#define SDLK_O 'O'
#define SDLK_P 'P'
#define SDLK_Q 'Q'
#define SDLK_R 'R'
#define SDLK_S 'S'
#define SDLK_T 'T'
#define SDLK_U 'U'
#define SDLK_V 'V'
#define SDLK_W 'W'
#define SDLK_X 'X'
#define SDLK_Y 'Y'
#define SDLK_Z 'Z'
#define SDLK_LEFTBRACKET '['
#define SDLK_BACKSLASH '\\'
#define SDLK_RIGHTBRACKET ']'
@@ -120,6 +146,11 @@ typedef Uint32 SDL_Keycode;
#define SDLK_x 'x'
#define SDLK_y 'y'
#define SDLK_z 'z'
#define SDLK_LEFTBRACE '{'
#define SDLK_PIPE '|'
#define SDLK_RIGHTBRACE '}'
#define SDLK_TILDE '~'
#define SDLK_DELETE '\x7F'
#define SDLK_CAPSLOCK SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK)
#define SDLK_F1 SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1)
#define SDLK_F2 SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2)
@@ -139,7 +170,6 @@ typedef Uint32 SDL_Keycode;
#define SDLK_INSERT SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT)
#define SDLK_HOME SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME)
#define SDLK_PAGEUP SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP)
#define SDLK_DELETE '\x7F'
#define SDLK_END SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END)
#define SDLK_PAGEDOWN SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN)
#define SDLK_RIGHT SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT)