MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Issues using the keyboard prefab on PC

Open StephenHodgson opened this issue 9 years ago • 33 comments

Overview

When using a uGUI text field and the virtual keyboard prefab on PC, both the virtual keyboard and OS keyboard shows up in the application.

HoloLens is unaffected.

Expected Behavior

A single keyboard

Actual Behavior

OS and keyboard prefab shows up

Steps to reproduce

  • Open keyboard test scene
  • Play in editor
  • Attempt to write in text field

Unity Editor Version

2017.2.0p1 MRTP4

Mixed Reality Toolkit Release Version

db59a1c7fa0c0c463466028c5f3e70088bbfda52

StephenHodgson avatar Nov 15 '17 16:11 StephenHodgson

This is still active in 2017.2.1p1

It also should be noted that even if you do not have uGUI elements in your scene the issue will still occur because of the InputField that is within the Keyboard.prefab itself.

markgrossnickle avatar Jan 05 '18 06:01 markgrossnickle

I found a less-than-perfect workaround: set KeyboardInputField 's interactable bool to false. This will prevent the OS keyboard from showing up, and upon user click, it brings up only the MRToolKit keyboard. However, this comes at a price... you would lose access to the interactable features of the InputField UI, such as highlighting selection and a blinking caret...

Like Mark mentioned, this also needs to be done for the InputField within the Keyboard.prefab itself. In addition, I recommend changing the Disabled colour to white and adding the following script into SliderInputField.cs to set caret position at the end upon user click:

    public override void OnPointerClick(PointerEventData eventData)
    {
        base.OnPointerClick(eventData);
        MoveTextEnd(false);
    }

MatrixInception avatar Jan 28 '18 17:01 MatrixInception

I am experiencing the same issue with my app. Unity documentation says: Windows Store Apps: On Universal Windows 10 Apps the touch screen keyboard is only supported in XAML based applications with touch input support. My app is with Build Type D3D and not xaml so this is the first strange thing. However since the keyboard is shown we can try to disable the touch input support. To do this we can define a new BaseInput used by the BaseInputModule where touchSupported is overrided and setted to false. BaseInputModule has a protected property m_InputOverride that we can use to tell unity to use the new BaseInput. That said, as a temporary workaround, I made the attached script that can be added to the EventSystem game object of the scene or to another game object (in the latter case you must set the field BaseInputModule with the current input module). In my case it seems to work (the native keyboard is not shown). Unity 2017.3.0f3 with HMD Can someone try this workaround so we can be more confident using it?. Thank you HideUnityTouchScreenKeyboard.zip HideUnityTouchScreenKeyboardC#4.zip

ivan2007 avatar Feb 09 '18 09:02 ivan2007

What changed in the last few days? The build on 2/06/18 did not bring up the OS keyboard now it does. Also in my project at least it opens the keyboard prefab, then opens the OS keyboard, then closes the OS keyboard and opens it again. I'm also using D3D as my build type which supposedly doesn't have an OS keyboard.

265lutab avatar Feb 09 '18 09:02 265lutab

@265lutab, I don't know. Can you try the workaround? Thanks

ivan2007 avatar Feb 09 '18 09:02 ivan2007

The build I made today does not show the system keyboard. I'm not aware of any changes I've made that would effect it. I don't know why it is now working correctly.

265lutab avatar Feb 09 '18 19:02 265lutab

In fact the builds I made that displayed the OS keyboard yesterday now don't. My guess is something in the mixed reality portal that was changed enabling the keyboards for a little while.

265lutab avatar Feb 09 '18 19:02 265lutab

Is anyone else still having the problem?

265lutab avatar Feb 09 '18 21:02 265lutab

@ivan2007 I did try bringing your script into the project anyways to see what would happen. I'm getting this error "Assets/Scripts/HideUnityTouchScreenKeyboard/HideUnityTouchScreenKeyboard.cs(14,49): error CS1644: Feature `expression bodied members' cannot be used because it is not part of the C# 4.0 language specification" I am using IL2CPP for my project.

265lutab avatar Feb 09 '18 21:02 265lutab

I have the Scripting Runtime Version set to 3.5 and the Api Compatibility Level set to 4.6. (I'm guessing the error is from the Scripting Runtime Version being 3.5 instead of 4.6.

265lutab avatar Feb 09 '18 21:02 265lutab

You can change the body of the property public override bool touchSupported { get { return false; } }

ivan2007 avatar Feb 09 '18 22:02 ivan2007

Thanks I did start having the keyboard error again so I used your script. It did mostly work for me. I'm not getting the system keyboard 90% of the time, but I did have it come up once. I haven't been able to repeat it so I'm not sure what caused it to be displayed. Do you know if there is a call that can be used to close the system keyboard as a backup if it opens for some users? I'm using Unity 2017.2.0p2-MRTP5

265lutab avatar Feb 13 '18 08:02 265lutab

@265lutab, TouchScreenKeyboard has a field 'active' but it is not static. The keyboard is opened by the InputField as you can see here (code from InputField):

 private void ActivateInputFieldInternal()
    {
      if ((UnityEngine.Object) EventSystem.current == (UnityEngine.Object) null)
        return;
      if ((UnityEngine.Object) EventSystem.current.currentSelectedGameObject != (UnityEngine.Object) this.gameObject)
        EventSystem.current.SetSelectedGameObject(this.gameObject);
      if (TouchScreenKeyboard.isSupported)
      {
        if (this.input.touchSupported)
          TouchScreenKeyboard.hideInput = this.shouldHideMobileInput;
        this.m_Keyboard = this.inputType != InputField.InputType.Password ? TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, this.inputType == InputField.InputType.AutoCorrect, this.multiLine) : TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, false, this.multiLine, true);
        this.MoveTextEnd(false);
      }
      else
      {
        this.input.imeCompositionMode = IMECompositionMode.On;
        this.OnFocus();
      }
      this.m_AllowInput = true;
      this.m_OriginalText = this.text;
      this.m_WasCanceled = false;
      this.SetCaretVisible();
      this.UpdateLabel();
    }

m_Keyboard is protected. You can make a script to access this field with reflection. During my test I noted that the script always work if you haven't set a breakpoint in the code (debug configuration) So when you build with Master or Release configuration in my case the script works.

ivan2007 avatar Feb 16 '18 08:02 ivan2007

@ivan2007 I tested the reflection code and it's not working on Hololens. As soon as an KeyboardInputField is focused, the console starts spamming NullReferenceExceptions. I read somewhere, that the Hololens requires the InputSystem to be the StandaloneInputModule.

Alexees avatar Feb 25 '18 07:02 Alexees

@Alexees Thanks for your test I don't know what you can do with HoloLens (I can't do any test on it). I saw that exception also without the script during the test with HMD. If you find any workaround please share here.

ivan2007 avatar Feb 25 '18 08:02 ivan2007

When the HoloLens gets the rs4 update this will no longer be a problem. Also reflection is probably not the best solution.

Simplest fix is to probably just check if the device is opaque and not do anything.

StephenHodgson avatar Feb 25 '18 15:02 StephenHodgson

Hi Stephen, I am sorry but I don't understand if your fix is also for HMD and where to check if the keyboard is opaque. However I have seen that the keyboard already uses a custom InputField (SliderInputField). If we make an override of LateUpdate like this: protected override void LateUpdate() { base.LateUpdate(); if (m_Keyboard != null ) { m_Keyboard.active = false; m_Keyboard = null; } } the problem seems fixed (no second keyboard appear and no exception is thrown). LateUpdate calls ActivateInputFieldInternal and opens the keyboard. The script is no more necessary. In my case I see that the keyboard is not null only one time Tested with Unity 2017.3.1p1 and HMD.

ivan2007 avatar Feb 25 '18 23:02 ivan2007

Editing my response above.

I meant to check if the device is opaque via holographic settings API.

StephenHodgson avatar Feb 25 '18 23:02 StephenHodgson

@ivan2007 I was wrong about your reflection fix, it could work on Hololens, the NullRef was caused by something else.

Alexees avatar Apr 09 '18 16:04 Alexees

@Alexees, to avoid reflection now I am using this (inside SliderInputField): protected override void LateUpdate() { try { base.LateUpdate(); } catch { } if (m_Keyboard != null) { m_Keyboard.active = false; m_Keyboard = null; } }

ivan2007 avatar Apr 09 '18 17:04 ivan2007