mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
Workaround for better AZERTY-Keyboard support
The first row of AZERTY-Keyboards (used in France and Belgium) doesn't have numbers as keys but ², &, é, ", ', (, -, è, _, ç, à, ), = (with small differences between France and Belgium). For some of those keys we don't have keycodes - and neither does SDL2. See also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 As a workaround, just map those keys to 1, 2, ..., 9, 0 anyway, as those are keys Quake2 already knows (and those chars are printed on the keys too, for typing they're reachable via shift). This workaround only works for SDL2, as SDL1.2 doesn't have scancodes which we need scancodes to identify the keys. While at it I unified handling of SDL_KEYDOWN and SDL_KEYUP, the code is almost identical anyway, apart from one bool argument to Key_Event(). We track this problem in #81
This commit is contained in:
parent
31ffb96614
commit
dc155cca9c
1 changed files with 27 additions and 17 deletions
|
@ -385,30 +385,40 @@ IN_Update(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
if ((event.key.keysym.sym >= SDLK_SPACE) &&
|
||||
(event.key.keysym.sym < SDLK_DELETE))
|
||||
{
|
||||
Key_Event(event.key.keysym.sym, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Key_Event(IN_TranslateSDLtoQ2Key(event.key.keysym.sym), true, true);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// fall-through
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
qboolean down = (event.type == SDL_KEYDOWN);
|
||||
|
||||
if ((event.key.keysym.sym >= SDLK_SPACE) &&
|
||||
(event.key.keysym.sym < SDLK_DELETE))
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// workaround for AZERTY-keyboards, which don't have 1, 2, ..., 9, 0 in first row:
|
||||
// always map those physical keys (scancodes) to those keycodes anyway
|
||||
// see also https://bugzilla.libsdl.org/show_bug.cgi?id=3188
|
||||
SDL_Scancode sc = event.key.keysym.scancode;
|
||||
if(sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_0)
|
||||
{
|
||||
Key_Event(event.key.keysym.sym, false, false);
|
||||
// Note that the SDL_SCANCODEs are SDL_SCANCODE_1, _2, ..., _9, SDL_SCANCODE_0
|
||||
// while in ASCII it's '0', '1', ..., '9' => handle 0 and 1-9 separately
|
||||
// (quake2 uses the ASCII values for those keys)
|
||||
int key = '0'; // implicitly handles SDL_SCANCODE_0
|
||||
if(sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_9)
|
||||
{
|
||||
key = '1' + (sc - SDL_SCANCODE_1);
|
||||
}
|
||||
Key_Event(key, down, false);
|
||||
}
|
||||
else
|
||||
#endif // SDL2; SDL1.2 doesn't have scancodes
|
||||
if ((event.key.keysym.sym >= SDLK_SPACE) &&
|
||||
(event.key.keysym.sym < SDLK_DELETE))
|
||||
{
|
||||
Key_Event(event.key.keysym.sym, down, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Key_Event(IN_TranslateSDLtoQ2Key(event.key.keysym.sym), false, true);
|
||||
Key_Event(IN_TranslateSDLtoQ2Key(event.key.keysym.sym), down, true);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
|
Loading…
Reference in a new issue