Small improvements to input code

This commit is contained in:
Daniel Gibson 2015-12-12 18:47:46 +01:00
parent dc155cca9c
commit 0fb8d80507

View file

@ -333,6 +333,7 @@ IN_Update(void)
break;
}
#endif
/* fall-through */
case SDL_MOUSEBUTTONUP:
switch( event.button.button )
{
@ -367,8 +368,8 @@ IN_Update(void)
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_TEXTINPUT:
if ((event.text.text[0] >= SDLK_SPACE) &&
(event.text.text[0] < SDLK_DELETE))
if((event.text.text[0] >= ' ') &&
(event.text.text[0] <= '~'))
{
Char_Event(event.text.text[0]);
}
@ -384,33 +385,32 @@ IN_Update(void)
Char_Event(event.key.keysym.unicode);
}
#endif
// fall-through
/* fall-through */
case SDL_KEYUP:
{
qboolean down = (event.type == SDL_KEYDOWN);
#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
/* 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)
{
// 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)
/* 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_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))
#endif /* SDL2; (SDL1.2 doesn't have scancodes so nothing we can do there) */
if((event.key.keysym.sym >= SDLK_SPACE) &&
(event.key.keysym.sym < SDLK_DELETE))
{
Key_Event(event.key.keysym.sym, down, false);
}
@ -428,7 +428,7 @@ IN_Update(void)
Key_MarkAllUp();
}
#else // SDL1.2
#else /* SDL1.2 */
case SDL_ACTIVEEVENT:
if(event.active.gain == 0 && (event.active.state & SDL_APPINPUTFOCUS))
{