Legacy:IsKeyPressed

From Spherical
Revision as of 22:01, 1 June 2013 by Apollolux (talk | contribs) (Notes: see also)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Check if a certain key is being held down on the keyboard.

Usage

boolean IsKeyPressed(key);



Examples

if (IsKeyPressed(KEY_ENTER))
{
  //Code
}

IsKeyPressed() is often used in conditions and loops. The above will check if the Enter key was pressed, and if so, it will run the condition.

You can use !IsKeyPressed to negate the function: if the key was NOT pressed.

if (!IsKeyPressed(KEY_ENTER))
{
  // ...

Notes

  • This function does not halt the engine like GetKey() does, and can therefore be used in continuous loops.
  • Do not use this function to check for key strokes. This function doesn't use a key queue, so it's suited for controlling a spaceship or a person on a map. However, if you need to pick up every key stroke (e.g. for a text box), use GetKey() instead.
  • If you need to find out if any key is being pressed, it's better to use the IsAnyKeyPressed() function.

See also