Reputation: 6140
I know how to hide or display Virtual Keyboard using InputMethodManager
.
But I want to enter text in EditText
using Physical keyboard but I don't want to display Virtual Keyboard in Unity 3D Android.
How can I do that in Unity 3D?
Upvotes: 0
Views: 6304
Reputation: 595
Old question I know, but what you really want is to set inputField.touchScreenKeyboard.active = false;
You may need to hold it false in a LateUpdate
[SerializeField]
private bool keyboardEnabled = true;
// toggle this to toggle native keyboard activity
public bool KeyboardEnabled { get { return keyboardEnabled; } set { keyboardEnabled = value; } }
private void LateUpdate()
{
#if UNITY_ANDROID
if (inputField.touchScreenKeyboard != null && !keyboardEnabled)
{
inputField.touchScreenKeyboard.active = false;
}
#endif
}
Upvotes: 1
Reputation: 125455
There is no such thing as EditText
in Unity. InputField
is used to receive input from a device.
You can disable Virtual Keyword with InputField
on Android. Not sure if this will work for other platforms.
Your InputField:
public InputField inputField;
Disable Virtual Keyboard:
inputField.keyboardType = (TouchScreenKeyboardType)(-1);
Enable Virtual Keyboard:
inputField.keyboardType = TouchScreenKeyboardType.Default;
If you run into weird issues, consider deriving your script from InputField
, then disable Virtual Keyboard and finally, call the base Start
function of the InputField
:
public class HideVirtualKeyboard : InputField
{
protected override void Start()
{
keyboardType = (TouchScreenKeyboardType)(-1);
base.Start();
}
}
Upvotes: 4