]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
add a helper function to release all keys "properly"
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 2 Aug 2011 18:58:57 +0000 (18:58 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 2 Aug 2011 18:58:57 +0000 (18:58 +0000)
(not used yet)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11263 d7cf8633-e32d-0410-b094-e92efae38249

keys.c
keys.h

diff --git a/keys.c b/keys.c
index ea6e2d5985c397392f77eb1563806ad25adde2b2..817ce92da6a38ae589788aa4f374b33ba420db61 100644 (file)
--- 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 c2587aed1b3a0796f25535a1d359982386759c06..e471a235a74ceb3255e0ed5732e76f79d8d29ac8 100644 (file)
--- 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);