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])
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. |
The current keyCode the combo is waiting for.
If the combo matches, will it delete itself?
A flag that controls if this Key Combo is actively processing keys or not.
The current index of the key being waited for in the 'keys' string.
An array of the keycodes that comprise this combo.
A reference to the Keyboard Manager
Has this Key Combo been matched yet?
The max delay in ms between each key press. Above this the combo is reset. 0 means disabled.
How far complete is this combo? A value between 0 and 1.
If previously matched and they press the first key of the combo again, will it reset?
If they press the wrong key do we reset the combo?
The length of this combo (in keycodes)
The time the previous key in the combo was matched.
The time the entire combo was matched.
Destroys this Key Combo and all of its references.