spinnerbox Posted June 15, 2016 Share Posted June 15, 2016 With some hacks from these two links: http://stackoverflow.com/questions/21406781/how-can-i-bring-up-the-keyboard-on-mobile-devices-to-catch-the-input-for-drawing?lq=1 I managed to open the keyboard on my android device. However the keystrokes i do are not sent to the Phaser game i.e my Phaser text field is not filled with data. <input id="hiddenInput" type="text" name="hiddenInput" style="position:absolute; left:-1px; top: -1px; width:1px; height:1px; opacity:0;"/> <script> $(document).ready( function() { $("#hiddenInput").focus(); }); </script> I am using Intel XDK and I upgraded my project to use cordova plugins. I installed ionic-plugin-keyboard but it behaves similar, i.e show/hide the keyboard but the input is not detected by Phaser. What do I miss to do or what do i do wrong? Any suggestions? Link to comment Share on other sites More sharing options...
symof Posted June 16, 2016 Share Posted June 16, 2016 You have 2 options: 1: You create a html input box and you make the user click it to open his keyboard, just as in the topic you linked. 2: You add an event and fire a function to open an alert prompt var game = new Phaser.Game(1024, 600, Phaser.auto, 'phaser', { preload: preload, create: create, update: update, render: render }); var result = 'Press a key'; function preload() { game.load.image('einstein', 'assets/pics/ra_einstein.png'); } function create() { einstein = game.add.sprite(50, 50, 'einstein'); einstein.inputEnabled = true; einstein.events.onInputDown.add(listener, this); } function update() { } function render(){ game.debug.text(result, 32, 32); } function listener () { var inputdata = prompt("Enter data", ""); result = inputdata; } spinnerbox 1 Link to comment Share on other sites More sharing options...
spinnerbox Posted September 27, 2017 Author Share Posted September 27, 2017 I can bring the keyboard up but it seems the input of the soft keyboard doesn't get to the canvas. it fills the hidden text box but the canvas doesn't react to it. The input from the soft keyboard just doesn't get detected by the canvas/javascript. Link to comment Share on other sites More sharing options...
samme Posted September 28, 2017 Share Posted September 28, 2017 The input doesn't do anything on its own, you have to listen for it, read it, and then do something with the contents. Link to comment Share on other sites More sharing options...
samme Posted September 28, 2017 Share Posted September 28, 2017 spinnerbox 1 Link to comment Share on other sites More sharing options...
spinnerbox Posted September 28, 2017 Author Share Posted September 28, 2017 11 hours ago, samme said: The input doesn't do anything on its own, you have to listen for it, read it, and then do something with the contents. I already have a keypress handler and the Android simulator with my game in it works well with the physical keyboard. Not sure why the same thing does not apply to the soft keyboard. but I will check your code sample. Maybe I miss something. Link to comment Share on other sites More sharing options...
spinnerbox Posted October 2, 2017 Author Share Posted October 2, 2017 On 9/28/2017 at 6:02 AM, samme said: I don't understad what is actually this.$input . Can you clarify? Also, is this the appropriate way to remove the event handler? this.inputListener = null; this.$input.removeEventListener('input', this.softKeyboardInputChanged); I need to add and remove the handler, all the time, i.e in periods. The keyboard is on until you hit the appropriate key combo or until a condition is met, then the event is removed and the keyboard becomes unusable. After a few seconds the keyboard gets enabled again and this repeats, over and over until all key combos are hit correctly. Link to comment Share on other sites More sharing options...
samme Posted October 2, 2017 Share Posted October 2, 2017 this.$input is the HTML element, <input>. removeEventListener needs a reference identical to the one given to addEventListener. I don't think you need to add or remove the handler again and again. Just check in the handler itself and do nothing if it's disabled. spinnerbox 1 Link to comment Share on other sites More sharing options...
Recommended Posts