Legacy:IsKeyPressed

From Spherical
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