JackAttack Posted July 12, 2017 Report Share Posted July 12, 2017 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); } and keyPress(key) { let character = String.fromCharCode(key.keyCode); this.keyInput += character; this.checkForCode(); } 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. Quote Link to comment Share on other sites More sharing options...
samme Posted July 12, 2017 Report Share Posted July 12, 2017 You can use game.input.keyboard.onPressCallback = function () {/*…*/}; JackAttack 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.