Jump to content

Keyboard input catchall listener?


Recommended Posts

I'm using the following code to capture key entry, just numbers for now, but I would like to capture all keys.

this.key0 = game.input.keyboard.addKey(Phaser.Keyboard.ZERO);
this.key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE);
this.key2 = game.input.keyboard.addKey(Phaser.Keyboard.TWO);
this.key3 = game.input.keyboard.addKey(Phaser.Keyboard.THREE);
this.key4 = game.input.keyboard.addKey(Phaser.Keyboard.FOUR);
this.key5 = game.input.keyboard.addKey(Phaser.Keyboard.FIVE);
this.key6 = game.input.keyboard.addKey(Phaser.Keyboard.SIX);
this.key7 = game.input.keyboard.addKey(Phaser.Keyboard.SEVEN);
this.key8 = game.input.keyboard.addKey(Phaser.Keyboard.EIGHT);
this.key9 = game.input.keyboard.addKey(Phaser.Keyboard.NINE);
for (let i = 0; i <= 9; ++i)
	this['key' + i].onDown.add(this.keyPress, this);


	let character = String.fromCharCode(key.keyCode);
	this.keyInput += character;

Do I need to call game.input.keyboard.addKey for every single key I want to detect? I feel like I missing be missing some functionality that listens for any key press.

This doesn't need to work on phones, the purpose is cheat code entry in a computer browser only for my own testing purposes.


Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...