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?

Share this post


Link to post
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;
}

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.