Pressing native keyboard's enter key only works once
Describe the bug
After closing the native keyboard with the enter key, future presses of the enter key don't do anything.
To reproduce
- Add empty gameobject that has
MixedRealityKeyboardcomponent - Add a button that invokes
MixedRealityKeyboard.ShowKeyboard - On device, press the button to show the keyboard.
- Close the keyboard using the enter key
- Repeat step 3 and try to repeat step 4
Expected behavior
The enter key should always close the keyboard
Your Setup (please complete the following information)
- Unity Version 2018.3.4f1
- MRTK Version v2.1
Target Platform (please complete the following information)
- HoloLens
- HoloLens 2
@kevbarn FYI I'm not sure if this is a duplicate of something that's being tracked on the OS side of the world. This isn't an MRTK issue (as it's part of system UI).
@bhtruong93 First, to double check, is the circled key what you mean by "enter key"?:

(The key will look different on HoloLens 1, but the placement will be similar).
If we are talking about the same key, this key doesn't close the keyboard. It just sends the key press to the app. The app is free to close the keyboard in response to this, which is what sounds like what is happening in this case. If the keyboard isn't closing in response to the enter key getting pressed, it's because the app isn't asking the keyboard to close.
@kevbarn yes that's what I meant. How do I capture that? As a test, I'm logging with something like this
public MixedRealityKeyboard keyboard;
private void Update()
{
if (keyboard.Visible)
{
Debug.Log(keyboard.Text.Length + ", " + keyboard.Text);
}
}
When pressing that key the first time, it closes and logs "0, ". Opening the keyboard again and pressing the key still results in "0, "
@bhtruong93, that's a good sanity check. I would expect this logging to produce the same output both times.
As far why the keyboard is closing the first time and not the second time, I'd look into your code more to see what is making the keyboard close. The keyboard does not close "automatically" in response to hitting the enter key.
You could try setting a break point on MixedRealityKeyboard.HideKeyboard() to see if that's the mechanism being used to close the keyboard. There are various other ways of closing the keyboard though, so it might be hard to track down. The most common way is using the Windows.UI.ViewManagement.InputPane class (which is what MixedRealityKeyboard uses internally). If any other components are referencing that class, you should take a look at them.
@kevbarn I'm actually in an empty scene besides a button that calls the keyboard to open (empty gameobject with MixedRealityKeyboard) and that's it. I don't have any of my scripts running in this scene.
Just to check, I added a log to MixedRealityKeyboard.HideKeyboard(), but it's not getting called the first time(or any time) when I press the enter key.
Hi @bhtruong93, I constructed my own test app following your directions. I'm using newer versions of both Unity and my HoloLens 2 OS though, so it isn't exactly the same. However, I'm unable to get the keyboard to close when pressing the Enter key on the keyboard, even the first time.
Again, this is what I would expect because the keyboard isn't designed to automatically close when the Enter key is pressed. It sounds like you might be hitting a bug that is fixed in a newer version of Unity or the HoloLens OS.
However, your "expected behavior" sounds like you DO want the keyboard to close consistently when pressing the Enter key. In this case, I suggest adding a component like this:
public Microsoft.MixedReality.Toolkit.Experimental.UI.MixedRealityKeyboard MRKeyboard;
void OnGUI()
{
if (Event.current.Equals(Event.KeyboardEvent(KeyCode.Return.ToString())))
{
MRKeyboard.HideKeyboard();
}
}
Where MRKeyboard is the same component that you called ShowKeyboard() with
@kevbarn ahh I see. Yeah I kind of expected the enter key not to close the keyboard either so we could handle it ourselves, but seeing it happen the first time made me think that’s just what it does here. I can’t update the Unity version, but that function will work. Thanks!