Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Input . Keyboard . KeyCombo

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Input . Keyboard . KeyCombo

A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them it will emit a keycombomatch event from the Keyboard Manager.

The keys to be listened for can be defined as:

A string (i.e. 'ATARI') An array of either integers (key codes) or strings, or a mixture of both An array of objects (such as Key objects) with a public 'keyCode' property

For example, to listen for the Konami code (up, up, down, down, left, right, left, right, b, a, enter) you could pass the following array of key codes:

this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true });

this.input.keyboard.on('keycombomatch', function (event) {
    console.log('Konami Code entered!');
});

Or, to listen for the user entering the word PHASER:

this.input.keyboard.createCombo('PHASER');

Constructor:

new KeyCombo(keyboardPlugin, keys, [config])

Parameters:

name type arguments description
keyboardPlugin Phaser.Input.Keyboard.KeyboardPlugin

A reference to the Keyboard Plugin.

keys string | Array.<number> | Array.<object>

The keys that comprise this combo.

config Phaser.Types.Input.Keyboard.KeyComboConfig <optional>

A Key Combo configuration object.

Since: 3.0.0

Members

current: number
Focus
Focus

Description:

The current keyCode the combo is waiting for.

Type:
number
Since: 3.0.0
Focus
Focus
deleteOnMatch: boolean
Focus
Focus

Description:

If the combo matches, will it delete itself?

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
enabled: boolean
Focus
Focus

Description:

A flag that controls if this Key Combo is actively processing keys or not.

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
index: number
Focus
Focus

Description:

The current index of the key being waited for in the 'keys' string.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
keyCodes: array
Focus
Focus

Description:

An array of the keycodes that comprise this combo.

Type:
array
Default: []
Since: 3.0.0
Focus
Focus

Description:

A reference to the Keyboard Manager

Type:
Since: 3.0.0
Focus
Focus
matched: boolean
Focus
Focus

Description:

Has this Key Combo been matched yet?

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
maxKeyDelay: number
Focus
Focus

Description:

The max delay in ms between each key press. Above this the combo is reset. 0 means disabled.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<private> onKeyDown: KeyboardKeydownCallback
Focus
Focus

Description:

The internal Key Down handler.

Type:
KeyboardKeydownCallback
Since: 3.0.0
Focus
Focus
<readonly> progress: number
Focus
Focus

Description:

How far complete is this combo? A value between 0 and 1.

Type:
number
Since: 3.0.0
Focus
Focus
resetOnMatch: boolean
Focus
Focus

Description:

If previously matched and they press the first key of the combo again, will it reset?

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
resetOnWrongKey: boolean
Focus
Focus

Description:

If they press the wrong key do we reset the combo?

Type:
boolean
Default: 0
Since: 3.0.0
Focus
Focus
size: number
Focus
Focus

Description:

The length of this combo (in keycodes)

Type:
number
Since: 3.0.0
Focus
Focus
timeLastMatched: number
Focus
Focus

Description:

The time the previous key in the combo was matched.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
timeMatched: number
Focus
Focus

Description:

The time the entire combo was matched.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Destroys this Key Combo and all of its references.

Examples:
Since: 3.0.0
Focus
Focus