Contains the keyboard information in the last frame. It uses the code property of the js keyboard event.

KeyboardEvent: code property

const keyboard = this.inputManager.keyboard;

if (keyboard.isPressed("ArrowRight")) {
// if the right arrow key is pressed, do some action
}

if (keyboard.orPressed("Enter", "Space")) {
// if the enter key or space key are pressed, do some action
}

if (keyboard.andPressed("ControlLeft", "KeyC")) {
// if the left control key and the letter C key are pressed, do some action
}

Constructors

Properties

pressedKeys: string[] = []

The current pressed key codes

Methods

  • This method accepts two parameters that will be returned depending on whether all the given keys are being pressed.

    Type Parameters

    • T

    Parameters

    • keyCodes: string[]

      The codes of the keys to check

    • returnTrue: T

      The value to return if the key is pressed

    • returnFalse: T

      The value to return if the key is not pressed

    Returns T

    The returnTrue for pressed or the returnFalse instead

  • This method accepts two parameters that will be returned depending on whether the key is pressed or not.

    Type Parameters

    • T

    Parameters

    • keyCode: string

      The code of the key to check

    • returnTrue: T

      The value to return if the key is pressed

    • returnFalse: T

      The value to return if the key is not pressed

    Returns T

    The returnTrue for pressed or the returnFalse instead

  • This method accepts two parameters that will be returned depending on whether one of the given keys is being pressed.

    Type Parameters

    • T

    Parameters

    • keyCodes: string[]

      The codes of the keys to check

    • returnTrue: T

      The value to return if the key is pressed

    • returnFalse: T

      The value to return if the key is not pressed

    Returns T

    The returnTrue for pressed or the returnFalse instead