AreKeysLeft

From Spheriki

Jump to: navigation, search

Checks whether there are keys present in the key buffer. Returns true if there are keys in the buffer, or false if there are none.


Contents

Usage

boolean AreKeysLeft();


Examples

while (AreKeysLeft()) GetKey();

A common use of this function is to flush the key buffer without pausing game execution, as demonstrated above.


// Processing here
// ...
while (AreKeysLeft())
{
  var k = GetKey();
  // Process input here
  // ...
}

The key buffer will generally always capture a key press, so it's useful for getting keyboard input from the player without worrying about missed keys. If the above example is placed in the logic of a bigger loop, all keys will always be processed.

Contrast this behaviour with the IsKeyPressed() and IsAnyKeyPressed() functions, which only check the key state when Sphere calls them, and may be prone to not detecting key strokes between calls.


Notes

  • This function goes hand-in-hand with the GetKey() function, which operates on the same key buffer.
  • AreKeysLeft() does not block execution, unlike GetKey(). This can be used to simulate non-blocking calls to GetKey(), which may be useful to retain access to the key buffer.


See also

Personal tools