Author Topic: Keyboard of Windows Store  (Read 6926 times)

Ana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Keyboard of Windows Store
« 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? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keyboard of Windows Store
« Reply #1 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.

EBailey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Keyboard of Windows Store
« Reply #2 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keyboard of Windows Store
« Reply #3 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.

EBailey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Keyboard of Windows Store
« Reply #4 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.

EBailey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile

Ana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Keyboard of Windows Store
« Reply #6 on: June 08, 2014, 09:56:12 AM »
So how can we use the touch keyboard with NGUI? Has it been fixed yet?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keyboard of Windows Store
« Reply #7 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.

MisterAndroid

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 3
    • View Profile
Re: Keyboard of Windows Store
« Reply #8 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keyboard of Windows Store
« Reply #9 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. <_<
« Last Edit: June 25, 2014, 05:50:24 AM by ArenMook »