Ak Pasaf
Ak Pasaf

Reputation: 237

Android Keyboard does not show when pressing input field in unity?

I have a simple scene in unity which has an input field in it. When I run my scene in my Android Device and press the input field, the android keyboard does not show. I am connecting via USB to my laptop using Unity Remote 5 app.

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class InputNumber : MonoBehaviour {

    public InputField input;

    // Use this for initialization
    void Start () {
        if (input)
        {
            TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
        }
        input.keyboardType = TouchScreenKeyboardType.NumberPad;
    }

    // Update is called once per frame
    void Update () {

    }
}

Upvotes: 2

Views: 18826

Answers (3)

Ashwin
Ashwin

Reputation: 7667

No need to call TouchScreenKeyboard.Open() method. The native keyboard will not show up if you are running it in Unity Remote app. But it will show up on touching input field once you build and run the app from File > Build Settings > Build or File > Build and Run.

Upvotes: 11

Programmer
Programmer

Reputation: 125455

When using the InputField component, you do not need TouchScreenKeyboard.Open to open the keyboard manually. Once the InputField is clicked on, it will open itself. Remove the unnecessary TouchScreenKeyboard.Open code.

I am connecting via USB to my laptop using Unity Remote 5 app.

That's the problem.

The InputField component will only open the keyboard when you build and run the program on the device. Unity Remote 5 is only used to detect touch on the screen and read the sensors such as the GPS and accelerometer sensors while programming on the Editor. For features supported with Unity Remote 5 see this post.

Also, TouchScreenKeyboard.Open will not work in the Editor too. You have to build and run it on the mobile device for it to work but TouchScreenKeyboard.Open is not needed here. Just build the game and deploy it to your device and the keyboard should open when you click on the InputField.

Upvotes: 4

Technivorous
Technivorous

Reputation: 1712

you need the Cross-Platform-Input asset from the Unity standard asset pack in the asset store. this is free, and once imported into your project will work on its own with the text field. just import it and try you phone again

then you wont need:

 if (input)
        {
            TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
        }
        input.keyboardType = TouchScreenKeyboardType.NumberPad;

Unitys mobile class will just open the keyboard when you tap the field. no extra coding needed.

Upvotes: 2

Related Questions