Detecting DoubleTap

So it seems KeyCombos are what I’m looking for?
http://localhost:8080/Phaser.Input.Keyboard.KeyCombo.html#maxKeyDelay__anchor

Testing it so far and the only problem is it seems there isn’t a unique identifier for the event other than the array of key codes.

https://labs.phaser.io/edit.html?src=src/input/keyboard/reset%20key%20combo%20on%20match.js

Add another key combo and test how to differentiate

How do you guys handle this ?

If you’re a reasonable human then you can inspect the keyCodes attribute of the parameter that gets passed into the callback:

    var combo = this.input.keyboard.createCombo('ABC', { resetOnMatch: true });
    var combo2 = this.input.keyboard.createCombo('AAA', { resetOnMatch: true });

    this.input.keyboard.on('keycombomatch', function (event) {
        console.log('Key Combo matched!' + event.keyCodes.join(', '));
    });

This will print the (numeric) keys that were pressed to trigger the combo.

If you’re an absurd human you’ll spend a month writing a library to handle arbitrary combo matching which will emit the named combo when it gets matched.

2 Likes

Currently having the approach of:

   var combo = this.input.keyboard.createCombo('ABC', { resetOnMatch: true });
    var combo2 = this.input.keyboard.createCombo('AAA', { resetOnMatch: true });

    this.input.keyboard.on('keycombomatch', function (event, keyEvent) {
        console.log(keyEvent.code); /// KeyA , the last key that is pressed in the key combo.
    });

since I’m only doing double taps for now, it’ll fine.