From 137357d6b7e13e7b2d4bbaeb719dfd4f218a1e5e Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 2 Aug 2011 18:58:57 +0000 Subject: [PATCH] add a helper function to release all keys "properly" (not used yet) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11263 d7cf8633-e32d-0410-b094-e92efae38249 --- keys.c | 15 +++++++++++++++ keys.h | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/keys.c b/keys.c index ea6e2d59..817ce92d 100644 --- a/keys.c +++ b/keys.c @@ -1959,6 +1959,21 @@ Key_Event (int key, int ascii, qboolean down) } } +// a helper to simulate release of ALL keys +void +Key_ReleaseAll (void) +{ + int key; + // clear the event queue first + eventqueue_idx = 0; + // then send all down events (possibly into the event queue) + for(key = 0; key < MAX_KEYS; ++key) + if(keydown[key]) + Key_Event(key, 0, false); + // now all keys are guaranteed down (once the event queue is unblocked) + // and only future events count +} + /* =================== Key_ClearStates diff --git a/keys.h b/keys.h index c2587aed..e471a235 100644 --- a/keys.h +++ b/keys.h @@ -377,7 +377,8 @@ void Key_Init(void); void Key_Shutdown(void); void Key_Init_Cvars(void); void Key_Event(int key, int ascii, qboolean down); -void Key_ClearStates (void); +void Key_ReleaseAll (void); +void Key_ClearStates (void); // FIXME: should this function still exist? Or should Key_ReleaseAll be used instead when shutting down a vid driver? void Key_EventQueue_Block(void); void Key_EventQueue_Unblock(void); -- 2.39.2