Skip to content

Commit

Permalink
Modifier keys on Mac OS X do not have scancodes
Browse files Browse the repository at this point in the history
This actually fixes three related issues:
- Modifier keys on OS X should have "unknown" scancodes
- Unknown scancodes on OS X should have the value 0, even though that
  conflicts with the scancode for "a"
- RGUI and RSHIFT should have scancodes on non-OSX platforms.

SDL 1.2's Quartz backend, used on Mac OS X, always gives modifier keys a
scancode of 0, even though OS X actually does have a scancode number for
them. This can be seen (both for < OS X 10.3, where left and right
modifiers could not be distinguished, and for newer versions where they
can) in the implementation here:
https://github.com/libsdl-org/SDL-1.2/blob/02c0253780c8a36569b271500a37591ab80e923d/src/video/quartz/SDL_QuartzEvents.m#L475

Applications such as DOSBox rely heavily on this behaviour, and the keys
will not function in the default "usescancodes=true" mode if a scancode
other than 0 is returned for the right-hand-side modifier keys.

This can be seen in sdl12-compat GitHub issue #84, where the issue was
analysed:
#84 (comment)
  • Loading branch information
sulix authored and icculus committed Jun 10, 2021
1 parent f7e60cd commit e1d7b80
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/SDL12_compat.c
Expand Up @@ -2418,7 +2418,7 @@ Scancode20to12(SDL_Scancode sc)
CASESCANCODE20TO12(BACKSLASH, 0x33, 0x2A);
CASESCANCODE20TO12(BACKSPACE, 0x16, 0x33);
CASESCANCODE20TO12(C, 0x36, 0x08);
CASESCANCODE20TO12(CAPSLOCK, 0x42, 0x39);
CASESCANCODE20TO12(CAPSLOCK, 0x42, 0x00);
CASESCANCODE20TO12(COMMA, 0x3B, 0x2B);
CASESCANCODE20TO12(D, 0x28, 0x02);
CASESCANCODE20TO12(DELETE, 0x00, 0x75);
Expand Down Expand Up @@ -2466,12 +2466,12 @@ Scancode20to12(SDL_Scancode sc)
CASESCANCODE20TO12(KP_PERIOD, 0x5B, 0x41);
CASESCANCODE20TO12(KP_PLUS, 0x56, 0x44);
CASESCANCODE20TO12(L, 0x2E, 0x25);
CASESCANCODE20TO12(LALT, 0x40, 0x3A);
CASESCANCODE20TO12(LCTRL, 0x25, 0x3B);
CASESCANCODE20TO12(LALT, 0x40, 0x00);
CASESCANCODE20TO12(LCTRL, 0x25, 0x00);
CASESCANCODE20TO12(LEFT, 0x00, 0x7B);
CASESCANCODE20TO12(LEFTBRACKET, 0x22, 0x21);
CASESCANCODE20TO12(LGUI, 0x85, 0x37);
CASESCANCODE20TO12(LSHIFT, 0x32, 0x38);
CASESCANCODE20TO12(LGUI, 0x85, 0x00);
CASESCANCODE20TO12(LSHIFT, 0x32, 0x00);
CASESCANCODE20TO12(M, 0x3A, 0x29);
CASESCANCODE20TO12(MINUS, 0x14, 0x1B);
CASESCANCODE20TO12(N, 0x39, 0x28);
Expand All @@ -2485,8 +2485,10 @@ Scancode20to12(SDL_Scancode sc)
CASESCANCODE20TO12(Q, 0x18, 0x0C);
CASESCANCODE20TO12(R, 0x1B, 0x0F);
CASESCANCODE20TO12(RETURN, 0x24, 0x24);
CASESCANCODE20TO12(RGUI, 0x86, 0x00);
CASESCANCODE20TO12(RIGHT, 0x00, 0x7C);
CASESCANCODE20TO12(RIGHTBRACKET, 0x23, 0x1E);
CASESCANCODE20TO12(RSHIFT, 0x3E, 0x00);
CASESCANCODE20TO12(S, 0x27, 0x01);
CASESCANCODE20TO12(SCROLLLOCK, 0x4E, 0x71);
CASESCANCODE20TO12(SEMICOLON, 0x2F, 0x29);
Expand All @@ -2503,13 +2505,9 @@ Scancode20to12(SDL_Scancode sc)
CASESCANCODE20TO12(Z, 0x34, 0x06);
#undef CASESCANCODE20TO12
default:
/* If we don't know it, return 0, which is "unknown" on everything
except Mac OS X, where it's "A" for whatever reason. */
#ifdef __MACOSX__
return 0x34; /* DOSBox should treat this as unknown. */
#else
/* If we don't know it, return 0, which is "unknown".
It's also "a" on Mac OS X, but SDL 1.2 uses it as "unknown", too. */
return 0;
#endif
}
return 0;
}
Expand Down

0 comments on commit e1d7b80

Please sign in to comment.