Search Feedback

1
votes

Stop InputField focus/selection from activating device's native keyboard

Input

-

-

Re-posted from Unity Answers: https://answers.unity.com/questions/1468733/how-can-i-stop-inputfield-focusselection-from-acti.html

I'm developing a Daydream application that uses the GVR keyboard for text input. I'd also really like to use Unity's native `InputField` so that I can take advantage of its many features, such as caret blinking. The problem is that `InputField` by default will always try to open the device's native keyboard when the input field is selected/activated/focused. That means that in VR, the 2D keyboard pops up on screen anytime an `InputField` is selected, which is a total blocker.

I've tried creating my own sub-class of `InputField`, but the best I could do was immediately hide the device-native keyboard after it was activated. This would result in an undesirable flicker on the screen. Here's what that code looked like, for reference:

using UnityEngine.EventSystems;
using UnityEngine.UI;

public class DaydreamInputField : InputField {

protected override void LateUpdate() {
base.LateUpdate();

if (m_Keyboard != null && m_Keyboard.active) {
m_Keyboard.active = false;
}
}
}

What I really need is a way to either tell the `InputField` to not open the keyboard or a way to set `TouchScreenKeyboard.isSupported` to `false` (or something along those lines). [Here are the lines of code I'm looking at](https://bitbucket.org/Unity-Technologies/ui/src/0155c39e05ca5d7dcc97d9974256ef83bc122586/UnityEngine.UI/UI/Core/InputField.cs?fileviewer=file-view-default#InputField.cs-1997:2012):

if (TouchScreenKeyboard.isSupported)
{
if (Input.touchSupported)
{
TouchScreenKeyboard.hideInput = shouldHideMobileInput;
}

m_Keyboard = (inputType == InputType.Password) ?
TouchScreenKeyboard.Open(m_Text, keyboardType, false, multiLine, true) :
TouchScreenKeyboard.Open(m_Text, keyboardType, inputType == InputType.AutoCorrect, multiLine);
}
else
{
Input.imeCompositionMode = IMECompositionMode.On;
OnFocus();
}

If that first `if` block was just `useKeyboard && TouchScreenKeyboard.isSupported` (or something like that) and `useKeyboard` was a public setter, that would be awesome!

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(9911)

2D

(260)

Ads

(50)

AI & Navigation

(77)

Analytics

(115)

Animation

(366)

Asset Store

(271)

Assets

(510)

Audio

(169)

Cloud Build

(122)

Collaborate

(45)

Docs & Tutorials

(217)

Editor

(2293)

Everyplay

(13)

Game Performance Reporting

(16)

General

(890)

Graphics

(821)

GUI

(397)

Input

(157)

Licensing

(84)

Networking

(176)

Physics

(362)

Platforms

(427)

Profiling & Optimization

(76)

Runtime

(171)

Scripting

(1097)

Terrain

(164)

WebGL

(138)