Phaser API Documentation

  Version: 
addKey(key, [enableCapture], [emitOnRepeat])

Description:

Adds a Key object to this Keyboard Plugin.

The given argument can be either an existing Key object, a string, such as A or SPACE, or a key code value.

If a Key object is given, and one already exists matching the same key code, the existing one is replaced with the new one.

Parameters:

name type arguments Default description
key string | number | Phaser.Input.Keyboard.Key

Either a Key object, a string, such as A or SPACE, or a key code value.

enableCapture boolean <optional> true

Automatically call preventDefault on the native DOM browser event for the key codes being added.

emitOnRepeat boolean <optional> false

Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default).

Returns:
Description:

The newly created Key object, or a reference to it if it already existed in the keys array.

Since: 3.10.0