Search Unity

InputField iOS keyboard problem

Discussion in 'UGUI & TextMesh Pro' started by pepipe, Jun 3, 2016.

  1. pepipe

    pepipe

    Joined:
    Jun 2, 2014
    Posts:
    10
    Hi,

    I have a input field that I only want to submit when I press "return" key or a button in the UI. In iOS when we focus the input field the iOS keyboard opens. That keyboard have a "done" and a "enter" buttons and I would like also to submit when the user press those.

    My question is how do I access those buttons? I research a bit about this but not getting luck. In docs I saw this: https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard-done.html

    The class InputField has the keyboard that TouchScreenKeyboard.Open returns but it's not accessable.

    Thanks
     
  2. crispybeans

    crispybeans

    Joined:
    Apr 13, 2015
    Posts:
    210
    If you want to access some functionality of the Keyboard the the InputField opens up one solution could be to tweak Keyboard.mm in the Generated XCode files?

    You can also look into using the events that are generated by the InputField. There is an event called OnSubmit - but I havent used it myself yet so i dont know if that's the exact thing out want to subscribe on.

    http://docs.unity3d.com/460/Documentation/ScriptReference/UI.InputField.OnSubmit.html
     
  3. PrinceLing

    PrinceLing

    Joined:
    Jun 8, 2016
    Posts:
    5
    Hi,I solve the problem when press "return" to call a event in iOS。

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Text;
    6. using UnityEngine.Events;
    7. using System;
    8. using UnityEngine.EventSystems;
    9. using UnityEngine.Serialization;
    10.  
    11. public class SubmitInputField : InputField
    12. {
    13.     [Serializable]
    14.     public class KeyboardDoneEvent : UnityEvent { }
    15.  
    16.     [SerializeField]
    17.     private KeyboardDoneEvent m_keyboardDone = new KeyboardDoneEvent();
    18.  
    19.     public KeyboardDoneEvent onKeyboardDone
    20.     {
    21.         get { return m_keyboardDone; }
    22.         set { m_keyboardDone = value; }
    23.     }
    24.  
    25.     void Update()
    26.     {
    27.         if (m_Keyboard != null && m_Keyboard.done && !m_Keyboard.wasCanceled)
    28.         {
    29.             m_keyboardDone.Invoke();
    30.         }
    31.     }
    32. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4. using UnityEngine.UI;
    5. using UnityEditor.UI;
    6.  
    7. [CustomEditor(typeof(SubmitInputField), true)]
    8. [CanEditMultipleObjects]
    9. public class SubmitInputFieldEditor : InputFieldEditor
    10. {
    11.     SerializedProperty m_KeyboardDoneProperty;
    12.     SerializedProperty m_TextComponent;
    13.  
    14.     protected override void OnEnable()
    15.     {
    16.         base.OnEnable();
    17.         m_KeyboardDoneProperty = serializedObject.FindProperty("m_keyboardDone");
    18.         m_TextComponent = serializedObject.FindProperty("m_TextComponent");
    19.     }
    20.  
    21.  
    22.     public override void OnInspectorGUI()
    23.     {
    24.         base.OnInspectorGUI();
    25.         EditorGUI.BeginDisabledGroup(m_TextComponent == null || m_TextComponent.objectReferenceValue == null);
    26.  
    27.         EditorGUILayout.Space();
    28.  
    29.         serializedObject.Update();
    30.         EditorGUILayout.PropertyField(m_KeyboardDoneProperty);
    31.         serializedObject.ApplyModifiedProperties();
    32.  
    33.         EditorGUI.EndDisabledGroup();
    34.         serializedObject.ApplyModifiedProperties();
    35.     }
    36. }
    But In Android,the code don't work,and the onKeyboardDone same to OnEndEdit(In Android)