Jump to content

Recommended Posts

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

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;
}

 

Link to comment
Share on other sites

  • 1 year later...
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

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

 Share

  • Recently Browsing   0 members

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