Search Unity

Unity 4.5 - [Windows Store] Touch screen keyboard not working

Discussion in 'Windows' started by brunokeith, May 28, 2014.

  1. brunokeith

    brunokeith

    Joined:
    Oct 29, 2013
    Posts:
    6
    Hi, everyone!

    I updated to Unity 4.5 but the touchscreen keyboard doesn't work yet.
    I tried this:

    Code (csharp):
    1.  
    2. TouchScreenKeyboard keyboard = null;
    3.  
    4. void Start()
    5. {
    6.     keyboard = TouchScreenKeyboard.Open("Oi");
    7. }
    8.  
    Anyone with the same problem?
     
  2. EBailey

    EBailey

    Joined:
    Mar 3, 2013
    Posts:
    6
    +1 - Same problem here. The keyboard displays if I use a GUI.TextField, but not if I try to manually bring up the keyboard similar to what you show in your example.
     
  3. EBailey

    EBailey

    Joined:
    Mar 3, 2013
    Posts:
    6
    Anyone having any luck here? Any workarounds?
     
  4. songhaineng

    songhaineng

    Joined:
    Mar 31, 2014
    Posts:
    40
    if (GUI.Button(new Rect(10, 10, 200, 20), "test"))
    {
    temp = TouchScreenKeyboard.Open("text");
    temp.active = true;
    }
    like this
     
    brunokeith likes this.
  5. EBailey

    EBailey

    Joined:
    Mar 3, 2013
    Posts:
    6
    Thanks for the reply!

    Well, that did display the keyboard, but I don't seem to be getting any of the keys. Here's the sample code I'm using
    Code (csharp):
    1.  
    2. public class KeyboardTest : MonoBehaviour
    3. {
    4.     private string textFieldString = "text field";
    5.     private TouchScreenKeyboard keyboard = null;
    6.  
    7.     void OnGUI()
    8.     {
    9.         if (GUI.Button (new Rect (0, 10, 200, 32), textFieldString))
    10.         {
    11.             keyboard = TouchScreenKeyboard.Open(textFieldString);
    12.             keyboard.active = true;
    13.         }
    14.  
    15.         if (keyboard != null)
    16.         {
    17.             textFieldString = keyboard.text;
    18.         }
    19.     }
    20. }
    With this, the button initially says 'text field', but when pressed and the keyboard shows, the text is cleared and isn't updated when I use the on-screen keyboard.
     
  6. songhaineng

    songhaineng

    Joined:
    Mar 31, 2014
    Posts:
    40
    It just pop up the touch keyborad.But can't input some key to the text. I used NGUI so i changed some code.

    void OnSelect (bool isSelected)
    {
    if (mDoInit) Init();

    if (label != null && enabled && NGUITools.GetActive(gameObject))
    {
    if (isSelected)
    {
    mText = (!useLabelTextAtStart && label.text == mDefaultText) ? "" : label.text;
    label.color = activeColor;
    if (isPassword) label.password = true;

    #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY
    if (Application.platform == RuntimePlatform.IPhonePlayer ||
    Application.platform == RuntimePlatform.Android
    #if UNITY_WP8
    || Application.platform == RuntimePlatform.WP8Player
    #endif
    #if UNITY_BLACKBERRY
    || Application.platform == RuntimePlatform.BB10Player
    #endif
    )
    {
    if (isPassword)
    {
    mKeyboard = TouchScreenKeyboard.Open(mText, TouchScreenKeyboardType.Default, false, false, true);
    }
    else
    {
    mKeyboard = TouchScreenKeyboard.Open(mText, (TouchScreenKeyboardType)((int)type), autoCorrect);
    }
    }
    else
    #endif
    {
    Input.imeCompositionMode = IMECompositionMode.On;
    Transform t = label.cachedTransform;
    Vector3 offset = label.pivotOffset;
    offset.y += label.relativeSize.y;
    offset = t.TransformPoint(offset);
    Input.compositionCursorPos = UICamera.currentCamera.WorldToScreenPoint(offset);
    mKeyboard.active = true;
    }
    UpdateLabel();
    }
    else
    {
    #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY
    if (mKeyboard != null)
    {
    mKeyboard.active = false;
    }
    #endif
    if (string.IsNullOrEmpty(mText))
    {
    label.text = mDefaultText;
    label.color = mDefaultColor;
    if (isPassword) label.password = false;
    }
    else label.text = mText;

    label.showLastPasswordChar = false;
    Input.imeCompositionMode = IMECompositionMode.Off;
    RestoreLabel();
    }
    }
    }

    You can see the NGUI Uiinput.cs code.
     
  7. EBailey

    EBailey

    Joined:
    Mar 3, 2013
    Posts:
    6
    songhaineng, I might be misunderstanding your reply.

    Are you saying that with NGUI's UIInput.cs, it now shows the keyboard, but you still don't get any typing to show up?

    If so, that's the same problem I'm having.

    I'm using NGUI v3.6.2 and I've update the code correctly (and posted on the NGUI site), but still don't get any input.

    My previous post is a reduced example where it fails.

    Or, are you saying that after you modified UIInput.cs, it shows the keyboard and works?
     
  8. songhaineng

    songhaineng

    Joined:
    Mar 31, 2014
    Posts:
    40
    What is your email?I sent you an example.I used NGUI 2.7!
     
  9. brunokeith

    brunokeith

    Joined:
    Oct 29, 2013
    Posts:
    6
    Wow! It's easy!

    I didn't notice because on others platforms it's easier.
    One thing I realized is that the code does not work on funcion Start.
    And the TouchScreenKeyboard.active = false doesn't work either!
     
  10. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    TouchScreenKeyboard on Windows Store Apps is currently limited to opening the keyboard.
    To close it you need to simply focus some non-input control in XAML It closes automatically, when user touches somewhere.
    You can get input text from Input.inputString. You'll have to concat it, as it returns text entered during current frame.
     
    brunokeith likes this.
  11. EBailey

    EBailey

    Joined:
    Mar 3, 2013
    Posts:
    6
    Aurimas, is there a bug then with my example I provided above? The input is not available in my example and it is based on the example provided with the Unity documentation.
     
  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    TouchScreenKeyboard.text property is not supported on WSA, so it always returns empty string.
    Input.inputString returns text, entered during current frame, you can concatenate it.
     
    brunokeith likes this.
  13. anubhav756

    anubhav756

    Joined:
    Mar 25, 2014
    Posts:
    6
    Hi ......thanks for your code.....but I'm getting an error which says "mKeyboard does not exist in the current context"....

    I guess the only change you've made in the defalut code is the mKeyboard.active = true; and the error points to that line itself...

    Please help.....I have no idea about this problem...

    Thanks in advance
     
  14. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    From the code it looks like you should replace UNITY_WP8 by UNITY_WINRT.