From 7fecb975a28d5bfcafbc09090c8a604f4761302d Mon Sep 17 00:00:00 2001 From: divverent Date: Mon, 10 Jul 2017 12:43:27 +0000 Subject: [PATCH] SDL2: combine SDL_KEYDOWN events directly with following SDL_TEXTINPUT events when possible. This solves ` keypresses that open/close the console also typing in a character "once and for all". The ability to type the ` character into the console is not impaired by this as con_closeontoggleconsole's logic to by default ignore the toggleconsole key when in the console but not at the beginning of the line still applies. From: terencehill git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12335 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=50312b15cfb7bd198d25aef3e999effe67e67b4e --- vid_sdl.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/vid_sdl.c b/vid_sdl.c index 9fbe57c6..98d6567e 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -1218,12 +1218,14 @@ void Sys_SendKeyEvents( void ) static qboolean sound_active = true; int keycode; int i; + qboolean isdown; Uchar unicode; SDL_Event event; VID_EnableJoystick(true); while( SDL_PollEvent( &event ) ) + loop_start: switch( event.type ) { case SDL_QUIT: #ifdef DEBUGSDLEVENTS @@ -1240,8 +1242,31 @@ void Sys_SendKeyEvents( void ) Con_DPrintf("SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym); #endif keycode = MapKey(event.key.keysym.sym); + isdown = (event.key.state == SDL_PRESSED); + unicode = 0; + if(isdown) + { + if(SDL_PollEvent(&event)) + { + if(event.type == SDL_TEXTINPUT) + { + // combine key code from SDL_KEYDOWN event and character + // from SDL_TEXTINPUT event in a single Key_Event call +#ifdef DEBUGSDLEVENTS + Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text); +#endif + unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL); + } + else + { + if (!VID_JoyBlockEmulatedKeys(keycode)) + Key_Event(keycode, 0, isdown); + goto loop_start; + } + } + } if (!VID_JoyBlockEmulatedKeys(keycode)) - Key_Event(keycode, 0, (event.key.state == SDL_PRESSED)); + Key_Event(keycode, unicode, isdown); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: -- 2.39.2