Skip to content

Commit

Permalink
Add the raw platform specific key code to SDL_Keysym
Browse files Browse the repository at this point in the history
This allows applications to handle keys that SDL doesn't recognize, in a platform dependent way.

Fixes #6390
  • Loading branch information
slouken committed Jun 19, 2024
1 parent 9569848 commit 1e80a3b
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 147 deletions.
2 changes: 1 addition & 1 deletion include/SDL3/SDL_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef struct SDL_Keysym
SDL_Scancode scancode; /**< SDL physical key code - see SDL_Scancode for details */
SDL_Keycode sym; /**< SDL virtual key code - see SDL_Keycode for details */
SDL_Keymod mod; /**< current key modifiers */
Uint16 unused;
Uint16 raw; /**< The platform dependent scancode for this event */
} SDL_Keysym;

/* Function prototypes */
Expand Down
2 changes: 1 addition & 1 deletion include/SDL3/SDL_keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ typedef Uint32 SDL_Keycode;
#define SDLK_MEDIA_PREVIOUS_TRACK SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PREVIOUS_TRACK)
#define SDLK_MEDIA_STOP SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_STOP)
#define SDLK_MEDIA_EJECT SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_EJECT)
#define SDLK_MEDIA_PLAYPAUSE SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PLAYPAUSE)
#define SDLK_MEDIA_PLAY_PAUSE SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_PLAY_PAUSE)
#define SDLK_MEDIA_SELECT SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIA_SELECT)
#define SDLK_AC_NEW SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_NEW)
#define SDLK_AC_OPEN SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_OPEN)
Expand Down
4 changes: 2 additions & 2 deletions include/SDL3/SDL_scancode.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ typedef enum SDL_Scancode
SDL_SCANCODE_MEDIA_PREVIOUS_TRACK = 268, /**< Previous Track */
SDL_SCANCODE_MEDIA_STOP = 269, /**< Stop */
SDL_SCANCODE_MEDIA_EJECT = 270, /**< Eject */
SDL_SCANCODE_MEDIA_PLAYPAUSE = 271, /**< Play / Pause */
SDL_SCANCODE_MEDIA_SELECT = 272, /* Media Select */
SDL_SCANCODE_MEDIA_PLAY_PAUSE = 271, /**< Play / Pause */
SDL_SCANCODE_MEDIA_SELECT = 272, /* Media Select */

SDL_SCANCODE_AC_NEW = 273, /**< AC New */
SDL_SCANCODE_AC_OPEN = 274, /**< AC Open */
Expand Down
2 changes: 1 addition & 1 deletion src/core/haiku/SDL_BApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class SDL_BLooper : public BLooper
return;
}
HAIKU_SetKeyState(scancode, state);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, state, HAIKU_GetScancodeFromBeKey(scancode));
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, scancode, HAIKU_GetScancodeFromBeKey(scancode), state);

if (state == SDL_PRESSED && SDL_TextInputActive()) {
const int8 *keyUtf8;
Expand Down
10 changes: 4 additions & 6 deletions src/core/linux/SDL_evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,10 @@ void SDL_EVDEV_Poll(void)

/* Probably keyboard */
scan_code = SDL_EVDEV_translate_keycode(event->code);
if (scan_code != SDL_SCANCODE_UNKNOWN) {
if (event->value == 0) {
SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, SDL_RELEASED, scan_code);
} else if (event->value == 1 || event->value == 2 /* key repeated */) {
SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, SDL_PRESSED, scan_code);
}
if (event->value == 0) {
SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, event->code, scan_code, SDL_RELEASED);
} else if (event->value == 1 || event->value == 2 /* key repeated */) {
SDL_SendKeyboardKey(SDL_EVDEV_GetEventTimestamp(event), (SDL_KeyboardID)item->fd, event->code, scan_code, SDL_PRESSED);
}
SDL_EVDEV_kbd_keycode(_this->kbd, event->code, event->value);
break;
Expand Down
12 changes: 6 additions & 6 deletions src/core/openbsd/SDL_wscons_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,22 +560,22 @@ static void Translate_to_keycode(SDL_WSCONS_input_data *input, int type, keysym_
switch (keyDesc.command) {
case KS_Cmd_ScrollBack:
{
SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEUP);
SDL_SendKeyboardKey(0, input->keyboardID, 0, SDL_SCANCODE_PAGEUP, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
return;
}
case KS_Cmd_ScrollFwd:
{
SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_PAGEDOWN);
SDL_SendKeyboardKey(0, input->keyboardID, 0, SDL_SCANCODE_PAGEDOWN, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
return;
}
}
for (i = 0; i < sizeof(conversion_table) / sizeof(struct wscons_keycode_to_SDL); i++) {
if (conversion_table[i].sourcekey == group[0]) {
SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, conversion_table[i].targetKey);
SDL_SendKeyboardKey(0, input->keyboardID, group[0], conversion_table[i].targetKey, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
return;
}
}
SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_UNKNOWN);
SDL_SendKeyboardKey(0, input->keyboardID, group[0], SDL_SCANCODE_UNKNOWN, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
}

static void updateKeyboard(SDL_WSCONS_input_data *input)
Expand Down Expand Up @@ -809,13 +809,13 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
} break;
case WSCONS_EVENT_ALL_KEYS_UP:
for (i = 0; i < SDL_NUM_SCANCODES; i++) {
SDL_SendKeyboardKey(0, input->keyboardID, SDL_RELEASED, i);
SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)i, SDL_RELEASED);
}
break;
}

if (input->type == WSKBD_TYPE_USB && events[i].value <= 0xE7)
SDL_SendKeyboardKey(0, input->keyboardID, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)events[i].value);
SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)events[i].value, type == WSCONS_EVENT_KEY_DOWN ? SDL_PRESSED : SDL_RELEASED);
else
Translate_to_keycode(input, type, events[i].value);

Expand Down
4 changes: 2 additions & 2 deletions src/core/winrt/SDL_winrtapp_direct3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow ^ sender, W
template <typename BackButtonEventArgs>
static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args)
{
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, SDL_PRESSED, SDL_SCANCODE_AC_BACK);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, SDL_RELEASED, SDL_SCANCODE_AC_BACK);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_AC_BACK, SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_AC_BACK, SDL_RELEASED);

if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
args->Handled = true;
Expand Down
77 changes: 40 additions & 37 deletions src/events/SDL_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES] = {
/* 268 */ SDLK_MEDIA_PREVIOUS_TRACK,
/* 269 */ SDLK_MEDIA_STOP,
/* 270 */ SDLK_MEDIA_EJECT,
/* 271 */ SDLK_MEDIA_PLAYPAUSE,
/* 271 */ SDLK_MEDIA_PLAY_PAUSE,
/* 272 */ SDLK_MEDIA_SELECT,
/* 273 */ SDLK_AC_NEW,
/* 274 */ SDLK_AC_OPEN,
Expand Down Expand Up @@ -806,7 +806,7 @@ void SDL_ResetKeyboard(void)
#endif
for (scancode = (SDL_Scancode)0; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keystate[scancode] == SDL_PRESSED) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, SDL_RELEASED, scancode);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_RELEASED);
}
}
}
Expand Down Expand Up @@ -944,7 +944,7 @@ int SDL_SetKeyboardFocus(SDL_Window *window)
return 0;
}

static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state)
{
SDL_Keyboard *keyboard = &SDL_keyboard;
int posted;
Expand All @@ -953,10 +953,6 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo
Uint8 repeat = SDL_FALSE;
const Uint8 source = flags & KEYBOARD_SOURCE_MASK;

if (scancode == SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
return 0;
}

#ifdef DEBUG_KEYBOARD
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
state == SDL_PRESSED ? "pressed" : "released");
Expand All @@ -975,28 +971,34 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo
return 0;
}

/* Drop events that don't change state */
if (state) {
if (keyboard->keystate[scancode]) {
if (!(keyboard->keysource[scancode] & source)) {
keyboard->keysource[scancode] |= source;
if (scancode != SDL_SCANCODE_UNKNOWN && scancode < SDL_NUM_SCANCODES) {
/* Drop events that don't change state */
if (state) {
if (keyboard->keystate[scancode]) {
if (!(keyboard->keysource[scancode] & source)) {
keyboard->keysource[scancode] |= source;
return 0;
}
repeat = SDL_TRUE;
}
keyboard->keysource[scancode] |= source;
} else {
if (!keyboard->keystate[scancode]) {
return 0;
}
repeat = SDL_TRUE;
}
keyboard->keysource[scancode] |= source;
} else {
if (!keyboard->keystate[scancode]) {
return 0;
keyboard->keysource[scancode] = 0;
}
keyboard->keysource[scancode] = 0;
}

/* Update internal keyboard state */
keyboard->keystate[scancode] = state;
/* Update internal keyboard state */
keyboard->keystate[scancode] = state;

if (keycode == SDLK_UNKNOWN) {
keycode = keyboard->keymap[scancode];
if (keycode == SDLK_UNKNOWN) {
keycode = keyboard->keymap[scancode];
}

} else if (keycode == SDLK_UNKNOWN && rawcode == 0) {
/* Nothing to do! */
return 0;
}

if (source == KEYBOARD_HARDWARE) {
Expand Down Expand Up @@ -1070,6 +1072,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo
event.key.keysym.scancode = scancode;
event.key.keysym.sym = keycode;
event.key.keysym.mod = keyboard->modstate;
event.key.keysym.raw = (Uint16)rawcode;
event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.key.which = keyboardID;
posted = (SDL_PushEvent(&event) > 0);
Expand Down Expand Up @@ -1105,43 +1108,43 @@ int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch)

if (mod & SDL_KMOD_SHIFT) {
/* If the character uses shift, press shift down */
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, SDL_PRESSED, SDL_SCANCODE_LSHIFT, SDLK_UNKNOWN);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, SDLK_UNKNOWN, SDL_PRESSED);
}

/* Send a keydown and keyup for the character */
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, SDL_PRESSED, code, SDLK_UNKNOWN);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, SDL_RELEASED, code, SDLK_UNKNOWN);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, code, SDLK_UNKNOWN, SDL_PRESSED);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, code, SDLK_UNKNOWN, SDL_RELEASED);

if (mod & SDL_KMOD_SHIFT) {
/* If the character uses shift, release shift */
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, SDL_RELEASED, SDL_SCANCODE_LSHIFT, SDLK_UNKNOWN);
SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, SDLK_UNKNOWN, SDL_RELEASED);
}
return 0;
}

int SDL_SendVirtualKeyboardKey(Uint64 timestamp, Uint8 state, SDL_Scancode scancode)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, state, scancode, SDLK_UNKNOWN);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDLK_UNKNOWN, state);
}

int SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode)
int SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, state, scancode, SDLK_UNKNOWN);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, SDLK_UNKNOWN, state);
}

int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode)
int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, state, scancode, keycode);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, keycode, state);
}

int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, SDL_PRESSED, scancode, SDLK_UNKNOWN);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDLK_UNKNOWN, SDL_PRESSED);
}

int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode)
int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state)
{
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE | KEYBOARD_IGNOREMODIFIERS, keyboardID, state, scancode, SDLK_UNKNOWN);
return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE | KEYBOARD_IGNOREMODIFIERS, keyboardID, rawcode, scancode, SDLK_UNKNOWN, state);
}

void SDL_ReleaseAutoReleaseKeys(void)
Expand All @@ -1152,7 +1155,7 @@ void SDL_ReleaseAutoReleaseKeys(void)
if (keyboard->autorelease_pending) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, SDL_RELEASED, scancode, SDLK_UNKNOWN);
SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDLK_UNKNOWN, SDL_RELEASED);
}
}
keyboard->autorelease_pending = SDL_FALSE;
Expand Down
6 changes: 3 additions & 3 deletions src/events/SDL_keyboard_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ extern int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch);
extern int SDL_SendVirtualKeyboardKey(Uint64 timestamp, Uint8 state, SDL_Scancode scancode);

/* Send a keyboard key event */
extern int SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state);
extern int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode);
extern int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state);

/* 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. */
extern int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, Uint8 state, SDL_Scancode scancode, SDL_Keycode keycode);
extern int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state);

/* Release all the autorelease keys */
extern void SDL_ReleaseAutoReleaseKeys(void);
Expand Down
2 changes: 1 addition & 1 deletion src/events/scancodes_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static SDL_Scancode const linux_scancode_table[] = {
/* 161, 0x0a1 */ SDL_SCANCODE_MEDIA_EJECT, /* KEY_EJECTCD */
/* 162, 0x0a2 */ SDL_SCANCODE_MEDIA_EJECT, /* KEY_EJECTCLOSECD */
/* 163, 0x0a3 */ SDL_SCANCODE_MEDIA_NEXT_TRACK, /* KEY_NEXTSONG */
/* 164, 0x0a4 */ SDL_SCANCODE_MEDIA_PLAYPAUSE, /* KEY_PLAYPAUSE */
/* 164, 0x0a4 */ SDL_SCANCODE_MEDIA_PLAY_PAUSE, /* KEY_PLAYPAUSE */
/* 165, 0x0a5 */ SDL_SCANCODE_MEDIA_PREVIOUS_TRACK, /* KEY_PREVIOUSSONG */
/* 166, 0x0a6 */ SDL_SCANCODE_MEDIA_STOP, /* KEY_STOPCD */
/* 167, 0x0a7 */ SDL_SCANCODE_MEDIA_RECORD, /* KEY_RECORD */
Expand Down
2 changes: 1 addition & 1 deletion src/events/scancodes_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static const SDL_Scancode windows_scancode_table[] = {
/*0xe01f*/ SDL_SCANCODE_UNKNOWN,
/*0xe020*/ SDL_SCANCODE_MUTE,
/*0xe021*/ SDL_SCANCODE_UNKNOWN, /* LaunchApp2 */
/*0xe022*/ SDL_SCANCODE_MEDIA_PLAYPAUSE,
/*0xe022*/ SDL_SCANCODE_MEDIA_PLAY_PAUSE,
/*0xe023*/ SDL_SCANCODE_UNKNOWN,
/*0xe024*/ SDL_SCANCODE_MEDIA_STOP,
/*0xe025*/ SDL_SCANCODE_UNKNOWN,
Expand Down
2 changes: 1 addition & 1 deletion src/events/scancodes_xfree86.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static const SDL_Scancode xfree86_scancode_table2[] = {
/* 161, 0x0a1 */ SDL_SCANCODE_MEDIA_EJECT, /* XF86Eject */
/* 162, 0x0a2 */ SDL_SCANCODE_MEDIA_EJECT, /* XF86Eject */
/* 163, 0x0a3 */ SDL_SCANCODE_MEDIA_NEXT_TRACK, /* XF86AudioNext */
/* 164, 0x0a4 */ SDL_SCANCODE_MEDIA_PLAYPAUSE, /* XF86AudioPlay */
/* 164, 0x0a4 */ SDL_SCANCODE_MEDIA_PLAY_PAUSE, /* XF86AudioPlay */
/* 165, 0x0a5 */ SDL_SCANCODE_MEDIA_PREVIOUS_TRACK, /* XF86AudioPrev */
/* 166, 0x0a6 */ SDL_SCANCODE_MEDIA_STOP, /* XF86AudioStop */
/* 167, 0x0a7 */ SDL_SCANCODE_MEDIA_RECORD, /* XF86AudioRecord */
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/android/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int Android_OnPadDown(int device_id, int keycode)
if (item && item->joystick) {
SDL_SendJoystickButton(timestamp, item->joystick, button, SDL_PRESSED);
} else {
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, SDL_PRESSED, button_to_scancode(button));
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), SDL_PRESSED);
}
SDL_UnlockJoysticks();
return 0;
Expand All @@ -225,7 +225,7 @@ int Android_OnPadUp(int device_id, int keycode)
if (item && item->joystick) {
SDL_SendJoystickButton(timestamp, item->joystick, button, SDL_RELEASED);
} else {
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, SDL_RELEASED, button_to_scancode(button));
SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), SDL_RELEASED);
}
SDL_UnlockJoysticks();
return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/video/android/SDL_androidkeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static SDL_Scancode Android_Keycodes[] = {
SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
SDL_SCANCODE_MEDIA_PLAYPAUSE, /* AKEYCODE_MEDIA_PLAY_PAUSE */
SDL_SCANCODE_MEDIA_PLAY_PAUSE, /* AKEYCODE_MEDIA_PLAY_PAUSE */
SDL_SCANCODE_MEDIA_STOP, /* AKEYCODE_MEDIA_STOP */
SDL_SCANCODE_MEDIA_NEXT_TRACK, /* AKEYCODE_MEDIA_NEXT */
SDL_SCANCODE_MEDIA_PREVIOUS_TRACK, /* AKEYCODE_MEDIA_PREVIOUS */
Expand Down Expand Up @@ -330,12 +330,12 @@ static SDL_Scancode TranslateKeycode(int keycode)

int Android_OnKeyDown(int keycode)
{
return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, SDL_PRESSED, TranslateKeycode(keycode));
return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_PRESSED);
}

int Android_OnKeyUp(int keycode)
{
return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, SDL_RELEASED, TranslateKeycode(keycode));
return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_RELEASED);
}

SDL_bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this)
Expand Down
Loading

0 comments on commit 1e80a3b

Please sign in to comment.