Number Key Input

Hi y’all, Having some trouble getting input from the number keys (not on the num pad, just at the top of the keyboard). I’m creating keys like this:

one = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ONE);

Then I check whether the key was just pressed in a takeInput function that is called from the update function:

if(Phaser.Input.Keyboard.JustDown(one)) {
    // one things...
}

However, When I run my code in the debugger I find that JustDown always returns false even when I press 1. However, One is a set as a key object:

Key {keyCode: 32, originalEvent: KeyboardEvent, preventDefault: true, enabled: true, isDown: false, …}

Am I doing this wrong?

Hello @akruschwitz, i also tryed to use this keyboard addKey stuff and then i swicth to normal keydown event, what you can is, just try to use Phaser.Input.Keyboard.JustUp() event if it’s not that important for you when its pressed other wise i’m always using this:

this.input.keyboard.on(Phaser.Input.Keyboard.Events.ANY_KEY_DOWN, (event) => {
        switch(event.code) {
            case 'Digit1':
            case 'Numpad1':
               console.log('1 pressed');
            break;
        }
    });

Worked for me everytime.

Update:

Is it that // one thing part is ever working? it should work as far i know