Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Ana on May 27, 2014, 09:15:46 AM

Title: Keyboard of Windows Store
Post by: Ana on May 27, 2014, 09:15:46 AM
Unity 4.5 includes support for programmatically opening on screen keyboard in Windows Store Apps.
Will we get a NGUI fix that will allow input textboxes to trigger keyboard on Windows Store Apps? :)
Title: Re: Keyboard of Windows Store
Post by: ArenMook on May 28, 2014, 07:06:32 AM
At the top of UIInput.cs there is a define:
  1. #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY)
  2. #define MOBILE
  3. #endif
Change it to:
  1. #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID || UNITY_BLACKBERRY || UNITY_WINRT)
  2. #define MOBILE
  3. #endif
I think that should be enough.
Title: Re: Keyboard of Windows Store
Post by: EBailey on May 31, 2014, 09:03:37 AM
I've tried this with no luck.  Additionally, in UIInput::Update I added the check for the player type to make sure it went into the keyboard logic, and still it doesn't work. 

If I use a normal GUI.TextField, the keyboard will display.
Title: Re: Keyboard of Windows Store
Post by: ArenMook on May 31, 2014, 12:59:32 PM
Does it actually go into the keyboard logic? Can you use the TouchScreenKeyboard at all? It doesn't exist on desktop platforms at all.
Title: Re: Keyboard of Windows Store
Post by: EBailey on June 01, 2014, 06:37:20 AM
I used a Debug.Log statement and then ran the code on my Surface RT to verify that it does go into the code. 

That said, I did a sample test application to display the on-screen keyboard and it fails also when using TouchScreenKeyboard.Open("foo"), but does display if I use GUI.TextField, so I suspect the problem is on the Unity side.  I've posted to their forums and have not had any responses.
Title: Re: Keyboard of Windows Store
Post by: EBailey on June 03, 2014, 04:17:12 PM
Tracking thread on Unity Forums: http://forum.unity3d.com/threads/unity-4-5-windows-store-touch-screen-keyboard-not-working.248523/ (http://forum.unity3d.com/threads/unity-4-5-windows-store-touch-screen-keyboard-not-working.248523/)
Title: Re: Keyboard of Windows Store
Post by: Ana on June 08, 2014, 09:56:12 AM
So how can we use the touch keyboard with NGUI? Has it been fixed yet?
Title: Re: Keyboard of Windows Store
Post by: ArenMook on June 09, 2014, 03:10:57 AM
Issue is in Unity's side -- they didn't test this feature before pushing it, so no. You will need to wait for them to fix it.
Title: Re: Keyboard of Windows Store
Post by: MisterAndroid on June 24, 2014, 12:12:00 PM
Hey Guys,

So I ran into the same problem posted above and by combining information from: http://forum.unity3d.com/threads/unity-4-5-windows-store-touch-screen-keyboard-not-working.248523/#post-1650855 and what was posted here, the edits I made to UIInput.cs (NGUI version 3.5.5) were as follows:

  1. //Change definition of mobile to include UNITY_WINRT (Metro + WP8 )
  2. #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID || UNITY_BLACKBERRY || UNITY_WINRT)
  3.  

in OnSelectEvent()
  1. //Replace just adding the application.platform for WP8Player
  2. #if UNITY_WINRT
  3.     || Application.platform == RuntimePlatform.WP8Player
  4.     || Application.platform == RuntimePlatform.MetroPlayerARM
  5.     || Application.platform == RuntimePlatform.MetroPlayerX64
  6.     || Application.platform == RuntimePlatform.MetroPlayerX86
  7. #endif
  8. ...
  9.     mKeyboard = (inputType == InputType.Password) ?
  10.         TouchScreenKeyboard.Open(mValue, TouchScreenKeyboardType.Default, false, false, true) :
  11.         TouchScreenKeyboard.Open(mValue, (TouchScreenKeyboardType)((int)keyboardType), inputType == InputType.AutoCorrect, label.multiLine, false, false, defaultText);
  12.  
  13. //This is the only way the keyboard knows to be opened.
  14. #if UNITY_METRO
  15.     mKeyboard.active = true;
  16. #endif
  17.  

In the Mobile Update() function
  1. #if MOBILE
  2.         string mCached = "";
  3.  
  4.         void Update()
  5.         {
  6. #if UNITY_METRO
  7.         if ( isSelected )
  8.         {
  9.             string text = Input.inputString; //According to the unity forum, only way to detect key presses
  10.            
  11.             if( !String.IsNullOrEmpty(text) )
  12.             {
  13.                 if( text == "\b" ) //The only way to pick up on the backspace from Input.inputString
  14.                 {
  15.                     if( !String.IsNullOrEmpty(mCached) && !String.IsNullOrEmpty(value) )
  16.                     {
  17.                         mCached = mCached.Remove(mCached.Length - 1, 1);
  18.                         value = value.Remove(value.Length - 1, 1);
  19.                     }
  20.                 }
  21.                 else
  22.                 {
  23.                         //Since mKeyboard.text is always null, you have to accumulate the chars
  24.                         //found at the frame they are processed
  25.                         mCached += text;
  26.                         value += text;
  27.                 }
  28.             }
  29.         }
  30.     }
  31. #else
  32. ... //rest of the Mobile update function
  33.  

The limitations of this solution are that the only special keystrokes I could recognize were backspace. But it did allow us to write a simple register/login UI for our game. I hope this helps others with the same problem!

~Andrew
Title: Re: Keyboard of Windows Store
Post by: ArenMook on June 25, 2014, 05:35:35 AM
Thanks, unfortunately 3.6.5 code is a bit different, and most of it already happens in the Update() function... Also you should really use the UIInput's Insert function so that validation works properly.

P.S. That said though, I've merged your code in there, somewhat. No idea if it will work, naturally... but I did. <_<