Reference keyIsDown()

keyIsDown()

Returns true if the key it’s checking is pressed and false if not.

keyIsDown() is helpful when checking for multiple different key presses. For example, keyIsDown() can be used to check if both LEFT_ARROW and UP_ARROW are pressed:

if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
  // Move diagonally.
}

keyIsDown() can check for key presses using keyCode values, as in keyIsDown(37) or keyIsDown(LEFT_ARROW). Key codes can be found on websites such as keycode.info.

Examples

Syntax

keyIsDown(code)

Parameters

code
Number:

key to check.

Returns

Boolean: whether the key is down or not.
Notice any errors or typos? Please let us know. Please feel free to edit src/events/keyboard.js and open a pull request!

Related References