Create Key Combo

Detect a specific sequence of key presses (a combo) and trigger an event when the sequence is completed successfully.

Create Key Combo, running
1024 × 768
GitHub
class Example extends Phaser.Scene
{
    create ()
    {

        //  Here we'll create a simple key combo
        //  When you type in ABCD the event will be triggered on the entry of the final character (D)
        //  An incorrect key press will reset the combo back to the start again

        const combo = this.input.keyboard.createCombo('ABCD');

        this.input.keyboard.on('keycombomatch', event =>
        {

            console.log('Key Combo matched!');

        });

    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.CANVAS,
    parent: 'game-container',
    scene: Example
};

const game = new Phaser.Game(config);

More in Keyboard22 examples