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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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