Is there a way to keep the mobile keyboard open after the user submitted the text? At the moment, Unity automatically closes the keyboard if a user touches outside of the keyboard area or if the user submits the text (click “done”).
As an easy example, after sending a message in WhatsApp, the keyboard remains open so the user can type in the next message directly.
I would have a look at the InputField ui script. Unity provides these online and you can google for them. I’m assuming you are using an input field? The important thing with the keyboard is
public void DeactivateInputField()
{
// Not activated do nothing.
if (!m_AllowInput)
return;
m_HasDoneFocusTransition = false;
m_AllowInput = false;
if (m_TextComponent != null && IsInteractable())
{
if (m_WasCanceled)
text = m_OriginalText;
if (m_Keyboard != null)
{
m_Keyboard.active = false;
m_Keyboard = null;
}
m_CaretPosition = m_CaretSelectPosition = 0;
SendOnSubmit();
Input.imeCompositionMode = IMECompositionMode.Auto;
}
MarkGeometryAsDirty();
}
If you notice there is an m_Keyboard.active = false. This will turn off the keyboard. So you may just be able to block that out. Or, you can always call m_keyboard.active = true if you want to display the keyboard.
ah, I see. I assumed you had an input field where they were typing something into. So I was just suggesting you could modify the input field script to not close the keyboard when the input box is no longer focused.
I played a bit with the inputfield script but I couldn’t stop the keyboard from closing. I think the reason for that is the keyboard contains the logic for closing and therefore adding my own logic to the inputfield script is too late.
Soft / Virtual Keyboard behavior varies per platform. For instance on iOS, the keyboard remains visible even when focus is lost whereas on Android it does not. As such, you might be better served by implementing your own soft / virtual keyboard.
Creating own virtual keyboard is really not feasible if you need to support global audience. The best keyboard for a user that he is used to is his own mobile keyboard, supporting his locale. My problem is that I do an online search in Firebase that updates per typed character and would allow you also to scroll through the current result list. However on Android, as soon as you touch outside the keyboard to scroll the result list, the keyboard closes. That is very annoying and should be something that Unity allows me to decide whether it makes sense in the given context.
I’ve posted a feature request for this issue because I’ve tried everything to keep the keyboard open when focus is lost but I haven’t been able to do it. This one fix would increase the usability and flow of my app more than anything else, so I’m really hoping we get a fix for it.
Not sure if this will help or be a good solution but for IOS I ended up with an easier solution. Open Keyboard class from Xcode under Classes-UI. Search for “- (void)textInputLostFocus” function. Comment the codes inside this function. Thats all! Now whenever your inputfield loses its focus keyboard will remain visible. It will not close when you tap outside keyboard. You can close keyboard by tapping done or cancel button on top of keyboard.