Fix chat input key being sometimes registered twice
authoralfadur
Wed, 29 Nov 2017 13:54:39 +0100
changeset 12846 e5c461729fe3
parent 12845 b63ec501490b
child 12847 1aba77b2e4ac
child 12850 b148eefe45c1
Fix chat input key being sometimes registered twice
hedgewars/SDLh.pas
hedgewars/uChat.pas
--- a/hedgewars/SDLh.pas	Sat Nov 25 11:28:44 2017 -0500
+++ b/hedgewars/SDLh.pas	Wed Nov 29 13:54:39 2017 +0100
@@ -1112,6 +1112,7 @@
 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
 procedure SDL_StartTextInput; cdecl; external SDLLibName;
 procedure SDL_StopTextInput; cdecl; external SDLLibName;
+procedure SDL_FlushEvent(eventType: LongWord); cdecl; external SDLLibName;
 
 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
 
--- a/hedgewars/uChat.pas	Sat Nov 25 11:28:44 2017 -0500
+++ b/hedgewars/uChat.pas	Wed Nov 29 13:54:39 2017 +0100
@@ -1098,11 +1098,18 @@
 end;
 
 procedure chChat(var s: shortstring);
+var i: Integer;
 begin
     s:= s; // avoid compiler hint
     GameState:= gsChat;
     SDL_StopTextInput();
     SDL_StartTextInput();
+    //Make REALLY sure unexpected events are flushed (1 time is insufficient as of SDL 2.0.7)
+    for i := 1 to 2 do
+    begin
+        SDL_PumpEvents();
+        SDL_FlushEvent(SDL_TEXTINPUT);
+    end;
     //SDL_EnableKeyRepeat(200,45);
     if length(s) = 0 then
         SetLine(InputStr, '', true)