Need to disable keyboard for input field, but still allow text selection on tablet

I have an app that requires text highlighting (think of using a highlighter to mark text in a book). I have an input field which gets populated with text. I then use a modified input field script which allows me to capture selected text to add a highlight to the text with a button click.

However, while this works fine in the editor, when I build out to android, because of the keyboard and input box popup, I am unable to set the highlight.

I am able to disable the keyboard from popping up, by just removing the call to open, but this doesn’t allow me to select text in the input field directly.

Is there any way to allow text selection in the input field directly without having the tablet bring up a separate input box?

The input field is set to read only. I basically want to select the text, hit a button to highlight all without any additional popups. The app is being reviewed to convert to Unity from another engine, so it’s important that I can find ways to convert the features.

Thanks for any help provided.

Ok, figured out how to hide the keyboard and still allow selecting in the input box that is already there. Does anybody know how the double caret might be done? The popup input box gives you a start and end selection caret. Would like to reproduce this if possible.

Thanks for any help.

Can you explain how u achieved to hide keyboard, i tried with this upon press on input field, but it’s not the best solution.

 TouchScreenKeyboard keyboard = new TouchScreenKeyboard("", TouchScreenKeyboardType.NintendoNetworkAccount, false, false, false, false, "");
        keyboard.active = false;

Created a custom Input Field using unity UI code.
I think this was the part for the keyboard, which is just a modified method within the script.

private void ActivateInputFieldInternal()
    {
        if (EventSystem.current.currentSelectedGameObject != gameObject)
            EventSystem.current.SetSelectedGameObject(gameObject);

        //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);

        //    // Mimics OnFocus but as mobile doesn't properly support select all
        //    // just set it to the end of the text (where it would move when typing starts)
        //    MoveTextEnd(false);
        //}
        //else
        //{
        Input.imeCompositionMode = IMECompositionMode.On;
        //Input.imeCompositionMode = IMECompositionMode.Off;
            OnFocus();
        //}

        m_AllowInput = true;
        m_OriginalText = text;
        m_WasCanceled = false;
        SetCaretVisible();
        UpdateLabel();
    }

Mostly, it’s commenting out the Open call to keep the keyboard from opening, but there are other commented out parts. Our input field that we are using doesn’t allow editing, so I’m not sure if this will also block that or not.

1 Like

Can you please share custom input field script with us.

1 Like