JcKairos Posted December 8, 2017 Share Posted December 8, 2017 I am working on a game which allow the player to enter the answer for math questions. Codes for typing the numbers are working such as: key1 = this.game.input.keyboard.addKey(Phaser.Keyboard.ONE); key1.onDown.add(this.press1, this); However, I can't seem to get the minus(-) working, it does not even trigger the key pressed. keyminus = this.game.input.keyboard.addKey(Phaser.Keyboard.MINUS); keyminus.onDown.add(this.pressminus, this); Is there any way I can implement the typing of '-'? Link to comment Share on other sites More sharing options...
JcKairos Posted December 11, 2017 Author Share Posted December 11, 2017 Phaser.Keyboard.NUMPAD_SUBTRACT works but players normally use the minus key and not the number-pad, is there any other way to type "-"? Link to comment Share on other sites More sharing options...
candyfloss40 Posted December 11, 2017 Share Posted December 11, 2017 I have the same problem. The code for detecting input (Phaser.keyboard) works almost any input except minus and plus. Would like to know an answer for this too. Link to comment Share on other sites More sharing options...
samme Posted December 11, 2017 Share Posted December 11, 2017 I think you have to a keypress callback and check for charCode=45. Link to comment Share on other sites More sharing options...
JcKairos Posted December 11, 2017 Author Share Posted December 11, 2017 39 minutes ago, samme said: I think you have to a keypress callback and check for charCode=45. Tried it, works for other keys but not "-". Any other way? Link to comment Share on other sites More sharing options...
samme Posted December 11, 2017 Share Posted December 11, 2017 game.input.keyboard.addCallbacks(this, null, null, function (stringFromCharCode, event) { // stringFromCharCode === '-' ? console.log(stringFromCharCode, event); }); Link to comment Share on other sites More sharing options...
JcKairos Posted December 11, 2017 Author Share Posted December 11, 2017 19 minutes ago, samme said: game.input.keyboard.addCallbacks(this, null, null, function (stringFromCharCode, event) { console.log(stringFromCharCode, event); }); Got it working... for some reason the charCode was not 45 but 173... Thanks for the help Link to comment Share on other sites More sharing options...
Recommended Posts