Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on September 21, 2012, 03:26:54 AM

Title: Open IOS keyboard[SOLVED]
Post by: jeanfabre on September 21, 2012, 03:26:54 AM
Hi,

 Following a request: http://hutonggames.com/playmakerforum/index.php?topic=2187.0 (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
Title: Re: Open IOS keyboard
Post by: Sjones 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!
Title: Re: Open IOS keyboard
Post by: jeanfabre 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
Title: Re: Open IOS keyboard
Post by: Sjones 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?

Title: Re: Open IOS keyboard
Post by: jeanfabre 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
Title: Re: Open IOS keyboard
Post by: Sjones 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 :(
Title: Re: Open IOS keyboard
Post by: Sjones 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.
Title: Re: Open IOS keyboard
Post by: jeanfabre on September 27, 2012, 02:24:30 PM
Hey, very good news! hopefully this was the bug you had indeed.

 bye,

 Jean
Title: Re: Open IOS keyboard
Post by: Sjones 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();
}

}
}

}
}
Title: Re: Open IOS keyboard
Post by: jeanfabre 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
Title: Re: Open IOS keyboard
Post by: davidf 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:
(https://lh5.googleusercontent.com/-QnadnAPKytM/UInEyadEXbI/AAAAAAAAAH4/8QYKDOIPs4s/s750/Game+View.png)
(https://lh5.googleusercontent.com/-jARBosX4wAU/UIm-5Op-1lI/AAAAAAAAAG0/azejWXK2y9k/s382/Start.png)
(https://lh6.googleusercontent.com/-vg7VpWDcPH4/UInCsH-7z2I/AAAAAAAAAHg/pmtaYE2CVeg/s843/start+action+1.png)

(https://lh4.googleusercontent.com/-MO_dGpYhCWw/UIm-5aOOk5I/AAAAAAAAAHA/xZCIteqhUyQ/s320/Text+Edit.png)(https://lh3.googleusercontent.com/-vcB6oJrLxGs/UInEyYMPOjI/AAAAAAAAAH0/0o_B2xdFc8U/s476/Text+Edit+action.png)
Great action by the way!! Thanks

Davidf
Title: Re: Open IOS keyboard
Post by: Sjones 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.
Title: Re: Open IOS keyboard
Post by: jeanfabre on October 26, 2012, 01:11:51 AM
hi,

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

bye,

 Jean
Title: Re: Open IOS keyboard
Post by: davidf on October 26, 2012, 11:14:06 AM
Works GREAT!!! Thanks so much!
Title: Re: Open IOS keyboard[SOLVED]
Post by: MABManZ 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!
Title: Re: Open IOS keyboard[SOLVED]
Post by: jeanfabre on February 10, 2014, 03:19:48 AM
Hi,

 try this:

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Device)]
[Tooltip("Opens the native keyboard provided by OS on the screen")]
public class OpenDeviceKeyBoard : FsmStateAction
{
#if UNITY_IPHONE
[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 static TouchScreenKeyboard keyboard;


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

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

public override void OnEnter()
{
_done = false;

UnityEngine.Debug.Log("OpenDeviceKeyBoard OPEN");
if (keyboard == null)
{
keyboard = TouchScreenKeyboard.Open(text.Value,keyBoardType,autoCorrection.Value,multiLine.Value,secure.Value,alert.Value,textPlaceHolder.Value);


}else{
UnityEngine.Debug.Log("OpenDeviceKeyBoard OPEN NOT NULL");
}
}

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


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

if (!_done && keyboard.done)
{
keyboard = null;
_done = true;
UnityEngine.Debug.Log("OpenDeviceKeyBoard DONE");
Fsm.Event(done);
Finish();
}

}
}
#endif
}
}

bye,

 Jean
Title: Re: Open IOS keyboard[SOLVED]
Post by: Gevarre on May 08, 2014, 01:51:02 PM
Sorry, but I seem to be having the same issue. This is on iPod 5, ios 7.

I did the same as the others:
-Created a state with a gui button that calls the "Show Keyboard" state.
-The Show Keyboard state has the OpenDeviceKeyboard action.
-"Done" triggers the Finished event that goes back to the first state.

First time through everything works fine, but after clicking done on the keyboard, it goes back to the first state, but the second time through, the keyboard never appears.

I added a button and other diagnostics to the second state, so I know the wiring is working fine, there is just no keyboard. I am NOT doing anything with the "Active" section of the keyboard, as previously suggested.

Anyone else actually getting this to work?
Title: Re: Open IOS keyboard[SOLVED]
Post by: jeanfabre on May 09, 2014, 04:16:06 AM
Hi,

 testing and it's really weird, it seems the second time doesn't register. I am trying to mess around with it to no availability.

So indeed, there is something not working properly, but I can't nail exactly what and why...

Bye,

 Jean
Title: Re: Open IOS keyboard[SOLVED]
Post by: jeanfabre on May 09, 2014, 04:30:59 AM
Hi,

 ok, found the issue ( internal flag not being reset properly).

 please download the new file from this location now ( will be served by the upcoming ecosystem browser).

https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/cd769d34222b8aca2515531c132a407162b90e26/Assets/PlayMaker%20Custom%20Actions/Device/OpenDeviceKeyBoard.cs

bye,

 Jean
Title: Re: Open IOS keyboard[SOLVED]
Post by: Gevarre on May 09, 2014, 12:03:25 PM
Perfect. Works just fine now.

As always, thanks for the amazingly fast fix ;D

And not to get greedy, but now that it's working, would it be possible to have an option so that when it opens again, the text field could be reset to blank instead of retaining the previous entry?

I don't know if that's even possible since it's Apple's built-in keyboard, but if not, does anyone know of the series of actions I would use to clear that field after I store it's contents in a variable. I'm doing kind of a data entry app, and having to hit that little "x" in the field for hundreds of consecutive entries will get rather tedious.
Title: Re: Open IOS keyboard[SOLVED]
Post by: jeanfabre on May 13, 2014, 07:39:14 AM
Hi,

it uses the content of the "text" variable you use. so you need to use "set string value" and set that variable to an empty string and then open the keyboard.

 Have you tried that already?

bye,

 Jean
Title: Re: Open IOS keyboard[SOLVED]
Post by: keziahwen on December 14, 2014, 01:11:25 AM
Hi Jean,

I have a problem getting updated value from the "text"
basically, i have two buttons doing math, one is subtotal, and the other one is total. so when the player enter value in "subtotal", the "total" button value should be changed according to the entry.
so when the first time i open the keyboard and type the value in subtotal, it all shows fine -- value display on both "subtotal" and "total"
however, when i click on the subtotal again to modify the value, it only shows fine on the "subtotal" but not the "total" (total still showing the previous value).

can you help?
ps i updated the cs file you attached before, still not working..

thanks
Title: Re: Open IOS keyboard[SOLVED]
Post by: keziahwen on December 14, 2014, 03:43:38 AM
Hi all again,

i sort it out already.....
i add another line of code to reset the text value so whenever you click the button again, the value will be reset.

cheers
Title: Re: Open IOS keyboard[SOLVED]
Post by: joel.carlson on March 12, 2015, 06:24:25 PM
Is this action still working? I'm trying it on my Android build and nothing is coming up when I add it to my state.