events: Add function to send keystrokes and not update the modifier state
Add SDL_SendKeyboardKeyIgnoreModifiers() function and repurpose the source parameter for the SDL_SendKeyboardKeyInternal() function to use as a generic set of keyboard flags.
This commit is contained in:
parent
59ad6793b9
commit
d2917918c0
2 changed files with 60 additions and 45 deletions
|
@ -30,8 +30,14 @@
|
|||
|
||||
/* Global keyboard information */
|
||||
|
||||
#define KEYBOARD_HARDWARE 0x01
|
||||
#define KEYBOARD_AUTORELEASE 0x02
|
||||
typedef enum
|
||||
{
|
||||
KEYBOARD_HARDWARE = 0x01,
|
||||
KEYBOARD_AUTORELEASE = 0x02,
|
||||
KEYBOARD_IGNOREMODIFIERS = 0x04
|
||||
} SDL_KeyboardFlags;
|
||||
|
||||
#define KEYBOARD_SOURCE_MASK (KEYBOARD_HARDWARE | KEYBOARD_AUTORELEASE)
|
||||
|
||||
typedef struct SDL_Keyboard SDL_Keyboard;
|
||||
|
||||
|
@ -789,13 +795,14 @@ void SDL_SetKeyboardFocus(SDL_Window *window)
|
|||
}
|
||||
}
|
||||
|
||||
static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint8 source, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
|
||||
static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, SDL_KeyboardFlags flags, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
|
||||
{
|
||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||
int posted;
|
||||
SDL_Keymod modifier;
|
||||
Uint32 type;
|
||||
Uint8 repeat = SDL_FALSE;
|
||||
const Uint8 source = flags & KEYBOARD_SOURCE_MASK;
|
||||
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
|
||||
return 0;
|
||||
|
@ -848,6 +855,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint8 source, Uint8 sta
|
|||
}
|
||||
|
||||
/* Update modifiers state if applicable */
|
||||
if (!(flags & KEYBOARD_IGNOREMODIFIERS)) {
|
||||
switch (keycode) {
|
||||
case SDLK_LCTRL:
|
||||
modifier = SDL_KMOD_LCTRL;
|
||||
|
@ -898,6 +906,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint8 source, Uint8 sta
|
|||
} else {
|
||||
keyboard->modstate &= ~modifier;
|
||||
}
|
||||
}
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
|
@ -973,6 +982,11 @@ int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
|
|||
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_PRESSED, scancode, SDLK_UNKNOWN);
|
||||
}
|
||||
|
||||
int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, Uint8 state, SDL_Scancode scancode)
|
||||
{
|
||||
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE | KEYBOARD_IGNOREMODIFIERS, state, scancode, SDLK_UNKNOWN);
|
||||
}
|
||||
|
||||
void SDL_ReleaseAutoReleaseKeys(void)
|
||||
{
|
||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||
|
|
|
@ -52,6 +52,7 @@ extern int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch);
|
|||
/* Send a keyboard key event */
|
||||
extern int SDL_SendKeyboardKey(Uint64 timestamp, Uint8 state, SDL_Scancode scancode);
|
||||
extern int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode);
|
||||
extern int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, Uint8 state, SDL_Scancode scancode);
|
||||
|
||||
/* This is for platforms that don't know the keymap but can report scancode and keycode directly.
|
||||
Most platforms should prefer to optionally call SDL_SetKeymap and then use SDL_SendKeyboardKey. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue