From: divverent Date: Tue, 2 Aug 2011 18:58:57 +0000 (+0000) Subject: add a helper function to release all keys "properly" X-Git-Tag: xonotic-v0.5.0~58 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c64a926edfcfa4cdcf629d63e843e5708354e050;p=xonotic%2Fdarkplaces.git 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 ::stable-branch::merge=137357d6b7e13e7b2d4bbaeb719dfd4f218a1e5e --- 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);