Class: KeyCombo

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');

new KeyCombo(keyboardPlugin, keys [, config])

Parameters:
Name Type Argument Description
keyboardPlugin Phaser.Input.Keyboard.KeyboardPlugin

A reference to the Keyboard Plugin.

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

The keys that comprise this combo.

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

A Key Combo configuration object.

Since: 3.0.0
Source: src/input/keyboard/combo/KeyCombo.js (Line 13)
Listens to Events:

Members


current :integer

The current keyCode the combo is waiting for.

Type:
  • integer
Since: 3.0.0
Source: src/input/keyboard/combo/KeyCombo.js (Line 114)

deleteOnMatch :boolean

If the combo matches, will it delete itself?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/keyboard/combo/KeyCombo.js (Line 202)

enabled :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/input/keyboard/combo/KeyCombo.js (Line 74)

index :integer

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

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/input/keyboard/combo/KeyCombo.js (Line 123)

keyCodes :array

An array of the keycodes that comprise this combo.

Type:
  • array
Since: 3.0.0
Default Value:
  • []
Source: src/input/keyboard/combo/KeyCombo.js (Line 84)

manager :Phaser.Input.Keyboard.KeyboardPlugin

A reference to the Keyboard Manager

Type:
Since: 3.0.0
Source: src/input/keyboard/combo/KeyCombo.js (Line 65)

matched :boolean

Has this Key Combo been matched yet?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/keyboard/combo/KeyCombo.js (Line 152)

maxKeyDelay :integer

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

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/input/keyboard/combo/KeyCombo.js (Line 182)

<readonly> progress :number

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

Type:
  • number
Since: 3.0.0
Source: src/input/keyboard/combo/KeyCombo.js (Line 252)

resetOnMatch :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/input/keyboard/combo/KeyCombo.js (Line 192)

resetOnWrongKey :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • 0
Source: src/input/keyboard/combo/KeyCombo.js (Line 172)

size :number

The length of this combo (in keycodes)

Type:
  • number
Since: 3.0.0
Source: src/input/keyboard/combo/KeyCombo.js (Line 133)

timeLastMatched :number

The time the previous key in the combo was matched.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/keyboard/combo/KeyCombo.js (Line 142)

timeMatched :number

The time the entire combo was matched.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/input/keyboard/combo/KeyCombo.js (Line 162)

Methods


destroy()

Destroys this Key Combo and all of its references.

Since: 3.0.0
Source: src/input/keyboard/combo/KeyCombo.js (Line 269)