Unity GUI: Input Field Keyboard issues android

Hi guys,

I’m developing a quiz like game for Android and I’m using the Input Field to accept input from user.
There is one issue which I’m facing, when I click on the input field, it launches the default keyboard and this keyboard hides the Input field.
How can I solve this?
In fact it would be great if you could give me ideas on how to implement a custom keyboard.

Thanks

I know this is question is a bit old, but as I visited it while looking for a solution to this same problem, I thought I could share what I did (tested on iOS and Android)

First, we created an empty child on the canvas named InputFieldFocusPivot, with the anchors set to the whole extents of the Canvas. We then moved into that object all the content that needs to be moved when an input field below the middle of the screen gets focused. We attached the following script to the InputFieldFocusPivot object:

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections;

public class InputFieldOnScreenManager : MonoBehaviour 
{

#if ( (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR)

   private InputField p_currentInput;

   private Vector3 p_originalPosition;

   void Start () 
   {
      p_currentInput = null;
   }

   void Update () 
   {
      if (p_currentInput != null)
      {
         // Check if current field stopped being focused
         if(p_currentInput.isFocused == false)
         {
            // If that is the case, restore content position
            transform.position = p_originalPosition;
            p_currentInput = null;
         } //endif
      }
      else
      {
         // Check if there is an object selected
         GameObject o = EventSystem.current.currentSelectedGameObject;
         if(o != null)
         {
            // Check if it is a focused input field
            InputField input = o.GetComponent<InputField>();
            if( (input != null) && (input.isFocused == true) )
            {
               // Take note of current position, to restore it when 
               // input field focus is lost
               p_originalPosition = transform.position;
               p_currentInput = input;

               // Check y-coordinate of bottom-left corner
               RectTransform inputTrans = input.transform as RectTransform;
               Vector3 botLeft = inputTrans.TransformPoint(inputTrans.rect.min);
               float delta = ( (Screen.height / 2f) - botLeft.y) + 20f;
               if(delta > 0f)
               {
                  // If it is below the middle of the screen, move it up
                  transform.Translate(0f, delta, 0f, Space.World);
               } //endif
            } //endif
         } //endif
      } //endif
   }

#endif

}

you can, it just involves a bit of mathematics with two Rect(s).

The way to check if two Rect(s) intersect is here (follow the Algorithm, its in C++ so don’t bother with Copying and pasting).

Custom Keyboard

As for the custom keyboard if your bent on making one, as I said its easy but kinda repetitive. Basically they I’d have it is to set up pages of Buttons. so you get your lower case, upper case symbols and numbers and whatever.

First Create a Panel name it keyboard ,and size it to your keyboard size, then create yet another panel , make it the parent of Keyboard and name it LowerCaseAlpha. Make these a Prefab and store in Resources Somewhere, this way you can call upon it anywhere in the game if for some reason it has been deleted from your scene.

Now create a bunch of buttons for your lower case, be sure to add a SHIFT button, A DONE or ENTER Button, A BACKSPACE button and a Symbol access button(on some keyboard sit looks like ±?!).

Repeat for the other pages as needed.

Now got to your keyboard object and create a Script called Onscreen Keyboard.
Now make a string variable for your text input, and maybe an UI reference variable called textOBject for what to send the text to.

Make a public function that has a string parameter and call it CharInput, this will appended you input to the end of the input string. if you want you have send the input string now to the InputField of you want to see it update as they type. Basically when you clisk a button, add a OnClick Receiver for it that and add your corresponding character to it.

public void CharInput(string myChar) {
   inputText += myChar;

}

Next , we need to add a backspace Event so your user can actually delete things. just make a public function That Shortens the string

public void Backspace() {
inputText = inputText.Remove(inputText.Length - 1);

}

Next is our Done or Accept Button. We just send off our input string to out InputField and we can either Hide or Destroy

public void AcceptInput(bool destroy = false) {


textObject.text = inputText;
//Null it for our next input if we don't destory
inputText = null;


if(destroy) {
   Destroy(gameObject);

}
else {
  gameObject.active = false;
}


}

Next is our Shift/Symbol Button, there alot of way to do this , the best is to keep all but the active pages hidden, and select them by deactivating all children then activate the one you want.

public void SelectPage(int index) {
//INDEX is the index child of the keyboard, 
//keep in mind of this when changing the order of pages

for(int i = 0; i < transform.childCount; i++) {
    var page = transform.GetChild(i)

     page.gameObject.enabled = false
     //activate of index matches
     if(i == index) {
      page.gameObject.enabled = true;
       }

}
}

Now on eachButton Create/Add a script tht will send you corresponding event and your pretty much done

Hope it helps