playMaker

Author Topic: Open IOS keyboard[SOLVED]  (Read 20296 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Open IOS keyboard[SOLVED]
« on: September 21, 2012, 03:26:54 AM »
Hi,

 Following a request: http://hutonggames.com/playmakerforum/index.php?topic=2187.0

Please find an action to open the IOS keyboard and get the inputed text.

It's tested on IOS, but not on android, should work tho.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Device)]
[Tooltip("Opens the native keyboard provided by OS on the screen")]
public class OpenDeviceKeyBoard : FsmStateAction
{
[Tooltip("The KeyBoard type")]
public TouchScreenKeyboardType keyBoardType;
[Tooltip("AutoCorrection setting")]
public FsmBool autoCorrection;
[Tooltip("single or multiline setting")]
public FsmBool multiLine;
[Tooltip("Hides inputed text")]
public FsmBool secure;
[Tooltip("Swith to Alert keyboard theme")]
public FsmBool alert;
[Tooltip("The placeholder text")]
public FsmString textPlaceHolder;


[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The text the user is entering")]
public FsmString text;

[Tooltip("Event sent when keyboard becomes active. Comes back to the state to keep using the keyboard")]
public FsmEvent active;

[Tooltip("Event sent when the user is done")]
public FsmEvent done;


private TouchScreenKeyboard keyboard;


private bool _active = false;
private bool _done = false;

public override void Reset()
{
keyBoardType = TouchScreenKeyboardType.Default;
autoCorrection = true;
multiLine = false;
secure = false;
alert = false;
textPlaceHolder = "";
}

public override void OnEnter()
{
if (keyboard == null)
{
keyboard = TouchScreenKeyboard.Open(text.Value,keyBoardType,autoCorrection.Value,multiLine.Value,secure.Value,alert.Value,textPlaceHolder.Value);
}
}

public override void OnUpdate()
{
if (keyboard != null)
{
text.Value = keyboard.text;


if (!_active && keyboard.active)
{
_active = true;
Fsm.Event(active);
}

if (!_done &&keyboard.done)
{
_done = true;
Fsm.Event(done);
Finish();
}

}
}

}
}

 Bye,

 Jean
« Last Edit: October 29, 2012, 01:23:14 AM by jeanfabre »

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Open IOS keyboard
« Reply #1 on: September 21, 2012, 01:27:03 PM »
thanks for this action!

I have tested it on an android device and the default keyboard doesnt work, this I was actually expecting so I don't think its an issue, the ascii keyboard setting looks like it should work as it comes up on screen.

I am having an issue, currently testing it on android as stated above.
on an android device  you can hide the keyboard (bottom left key of attached pic) this then brings a dialogue box with the text at the bottom of the screen with an ok button next to it, if you touch anywhere else on the game the box disappears and the fsm goes unresponsive ( game still runs and can press a reset button that is in a separate fsm, this also resets the on screen keyboard) only on the reset does the fsm go back to its proper behaviour

if you use the input properly once and close it using the done button the fsm responds as expected however when I try to re-open the on screen keyboard the text field goes back to the inputed text as expected however the on screen keyboard doesnt show with the same issue as touching off the keyboard.

This sounds like that they keyboard is being drawn behind the game and it can not be accessed any more, though this is a guess as I do not know how to get any more debug info out other than writing text to screen.

the functionality works perfectly though, I can input text and pass it on!
so a big thanks for the action so far!
« Last Edit: September 24, 2012, 09:19:35 AM by Sjones »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Open IOS keyboard
« Reply #2 on: September 24, 2012, 03:05:49 AM »
hi,

 I unfortunately do not own or have access to any android devices... if you can provide me a code that make the keyboard behave like you want, send it to me and I'll try and match it.

bye,

 Jean

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Open IOS keyboard
« Reply #3 on: September 24, 2012, 09:28:59 AM »
thank you for help, I looked at the help page on the subject and I cant see anything there that may help, as there is no on screen keyboard within the editor it is hard to debug

I will ask over at the unity forums but I have made a few observations, might point you in the right direction.

so after reading the comment about the active event, I used this to see when the state was active by posting text to screen, then on exit posted another comment.

so first open and close works as expected, the second time it goes to the "on screen keyboard state" the keyboard does not activate this time around and stops in that state, again game is still running, showing the fps counter I have placed on the UI changing as expected.

further more to the first post when minimising the keyboard and touching of screen on anywhere but the keyboard, pressing the back button (mapped to escape) on the device the keyboard seems to properly close and the game returns to normal.
this seems to support the idea that the keyboard is being rendered behind the game at this point and as such is a bug with unity?


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Open IOS keyboard
« Reply #4 on: September 25, 2012, 01:03:18 AM »
Hi,

 try no to use the active event at all, and see if it performs? maybe this is the problem.

bye,

 Jean

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Open IOS keyboard
« Reply #5 on: September 25, 2012, 08:42:10 AM »
thanks for the suggestion but unfortunately it makes no difference.

not too sure but it seems like android keyboard is buggy, sounds like similar issues to this http://forum.unity3d.com/threads/147669-Android-Keyboard-issues

the fix is in 4 which does not help me too much :(
« Last Edit: September 25, 2012, 08:56:14 AM by Sjones »

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Open IOS keyboard
« Reply #6 on: September 27, 2012, 11:26:45 AM »
the gods are smiling on me today!

unity3d 3.5.6 fix

Android: Made sure OnScreenKeyboard can be opened again after being closed due to lost focus.

might be part of the issue, I have yet to test it, but it makes me happy that there is a chance :D. will update here once I got the new version tested and all that.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Open IOS keyboard
« Reply #7 on: September 27, 2012, 02:24:30 PM »
Hey, very good news! hopefully this was the bug you had indeed.

 bye,

 Jean

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Open IOS keyboard
« Reply #8 on: October 07, 2012, 03:46:23 PM »
well I finally got around to testing this, many problems this week! :(

anyhow, good and better news here.

with the recent update the on screen keybaord was working better, now when you touch off the keyboard it sends the finished event, score 1 :D

the issue was then that this script would not re-open the keyboard for a second time, so after many different solutions that failed I commented out the if keyboard == null.

this then opend the keyboard up for a second time but would not send the active state or end state

so I then commented out all the private bool stuff in the script and after 2 hours of messing around got the script to work, im not entirely sure what the private bool tests where for.

at the moment I have only done a simple test with 1 input type and field etc, what does the private bool effect, will I have an issue if I open a different type of keyboard.

also when I re-open it the keybaord it has the old text, this is a minor issue but is there a way to reset the text to the place holder text with a bool option in the action.

for those with android devices and after onscreen keyboard, this is the code I used, modified from jean's code and use at your own risk (needs testing a bit more I think)

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Device)]
[Tooltip("Opens the native keyboard provided by OS on the screen")]
public class OpenDeviceKeyBoard : FsmStateAction
{
[Tooltip("The KeyBoard type")]
public TouchScreenKeyboardType keyBoardType;
[Tooltip("AutoCorrection setting")]
public FsmBool autoCorrection;
[Tooltip("single or multiline setting")]
public FsmBool multiLine;
[Tooltip("Hides inputed text")]
public FsmBool secure;
[Tooltip("Swith to Alert keyboard theme")]
public FsmBool alert;
[Tooltip("The placeholder text")]
public FsmString textPlaceHolder;


[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The text the user is entering")]
public FsmString text;

[Tooltip("Event sent when keyboard becomes active. Comes back to the state to keep using the keyboard")]
public FsmEvent active;

[Tooltip("Event sent when the user is done")]
public FsmEvent done;


private TouchScreenKeyboard keyboard;


// private bool _active = false;
// private bool _done = false;

public override void Reset()
{
keyBoardType = TouchScreenKeyboardType.Default;
autoCorrection = true;
multiLine = false;
secure = false;
alert = false;
textPlaceHolder = "";
}

public override void OnEnter()
//{
//if (keyboard == null)
{
keyboard = TouchScreenKeyboard.Open(text.Value,keyBoardType,autoCorrection.Value,multiLine.Value,secure.Value,alert.Value,textPlaceHolder.Value);
}
//}

public override void OnUpdate()
{
if (keyboard != null)
{
text.Value = keyboard.text;


if (keyboard.active)
{
// _active = true;
Fsm.Event(active);
}

if (keyboard.done)
{
// _done = true;
Fsm.Event(done);
Finish();
}

}
}

}
}
« Last Edit: October 07, 2012, 04:05:52 PM by Sjones »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Open IOS keyboard
« Reply #9 on: October 08, 2012, 01:09:56 AM »
Hi,

Good, I also found out that on IOS, if you close the keyboard with the bottom left button, then the top bar with the text input and done button stay up... crap.... so the user need to hit the "done" button instead, haven't really got to the bottom of this one, but just found out while testing something else actually.

bye,

 Jean

davidf

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Open IOS keyboard
« Reply #10 on: October 25, 2012, 05:31:49 PM »
I am using an Ipad
I just added this action and I am trying to use it with the tk2d textmesh.  I have a text variable that is being changed when I click on an object.  It works once, updates the text var and then closes the keyboard. I want to be able to touch it again.
When you do touch on then object again The even fires, but the keyboard does not come up again. It only comes up the first time. Any Ideas?

GAME VIEW:


Great action by the way!! Thanks

Davidf
« Last Edit: October 25, 2012, 07:10:24 PM by davidf »

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Open IOS keyboard
« Reply #11 on: October 26, 2012, 12:05:44 AM »
sounds similar to my issue however jean says he hasn't had an issue on the iphone/pad as such I would suggest not sending the active to an event, leave it blank and see if that fixes your issue.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Open IOS keyboard
« Reply #12 on: October 26, 2012, 01:11:51 AM »
hi,

 yes, sJones is correct, try without wiring the active event first.

bye,

 Jean

davidf

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Open IOS keyboard
« Reply #13 on: October 26, 2012, 11:14:06 AM »
Works GREAT!!! Thanks so much!
« Last Edit: October 26, 2012, 11:37:01 AM by davidf »

MABManZ

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 125
    • MABManZ.com
Re: Open IOS keyboard[SOLVED]
« Reply #14 on: February 08, 2014, 06:59:11 AM »
Hey, this action works great but is there any way to stop it from preventing a build to PC/non-mobile?

My game is multi-platform and I can't build to PC unless I actually DELETE the playmaker action file because of the error:

Assets/PlayMaker Custom Actions/OpenDeviceKeyBoard.cs(12,24): error CS0246: The type or namespace name `TouchScreenKeyboardType' could not be found. Are you missing a using directive or an assembly reference?



Thanks for the help!