I used the VirtualKeyboard Buildingblock to add the Keyboard to View. The documentation still states to update the "Text Commit Field". This is deprecated! You should add the a `OVRVirtualKeyboardInputFieldTextHandler` to a (legacy) TextField (it does not work with TextmeshPro). Then you can set your TextField as `TextHandler` of your `VirtualKeyboard` Gameobject.
So what I did, I created a `CustomOVRVirtualKeyboardInputFieldTextHandler` inheriting from `OVRVirtualKeyboardInputFieldTextHandler`. This one handles switching your keyboards context.
using UnityEngine;
using UnityEngine.UI;
class CustomOVRVirtualKeyboardInputFieldTextHandler : OVRVirtualKeyboardInputFieldTextHandler
{
public OVRVirtualKeyboard keyboard;
public new void Start()
{
InputField = GetComponent<InputField>();
keyboard.EnterEvent.AddListener(KeyboardEnter);
base.Start();
}
public void Update()
{
if (IsFocused) {
BindKeyboard();
}
// This works in debug mode. But when the game is built, the InputField loses focus on next frame, so the keyboard gets immediatly unbound.
// Tested with Meta XR SDK v60
// if (!IsFocused && (object)keyboard.TextHandler == this) {
// UnbindKeyboard();
// }
}
protected void KeyboardEnter()
{
UnbindKeyboard();
}
protected void BindKeyboard()
{
keyboard.TextHandler = this;
keyboard.gameObject.SetActive(true);
}
protected void UnbindKeyboard()
{
InputField.DeactivateInputField();
keyboard.gameObject.SetActive(false);
keyboard.TextHandler = null;
}
}
There is one catch. I noticed that the TextField loses focus on the next frame after clicking it. So I had to remove the `UnbindKeyboard()` from the Update-Method, when it is not focused anymore.
This does not happen when I run the App in Debug Mode (Unity "Play"-Button) and use it on my Quest 3 (via Link Cable). This only happens when I use "Build and Run" in Unity. I did not test it when I copy the app the my Quest 3 via Sideload yet, but I do not expect any difference.
PS: The `InputField` property gets set automatically, as it should of course always be the same InputField the component was added to. But as this field is `private` in the base class, I did not manage to hide it in the Editor. Tips on this is appreciated.