microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Support not closing UWP keyboard on air taps with TMP_InputField #10069

Closed hermann-noll closed 9 months ago

hermann-noll commented 3 years ago

Describe the problem

When TMP_InputField is used with the system keyboard air taps will cause the Hololens keyboard to close. This happens very easily, especially for unexperienced Hololens users.

Describe the solution you'd like

I would like an option to disable air taps closing the keyboard when using TMP_InputField.

Describe alternatives you've considered

There is a DisableUIInteractionWhenTyping property which unfortunately does not seem to do anything in regards to TMP_InputField. Alternatively I have tried setting the ProcessPaused property whenever the keyboard is visible (TouchScreenKeyboard.visible), but this also disables closing via the enter button.

feko006 commented 2 years ago

We were having the same issue and were able to find a workaround, so here it is in case anyone else experiences this :)

Note: I unfortunately do not have the time to submit a PR and I'm not even sure if this "fix" is the desired behaviour of MRTK with the ProcessPaused flag...

Step 1 - Register events for the input fields' onSelect and onDeselect events.

We have our own wrapper MonoBehaviour which we use for our input field logic, so the following code is from that wrapper class.

        private void Start()
        {
            ...
            _inputModule = CameraCache.Main.GetComponent<MixedRealityInputModule>();
            _inputField.onSelect.AddListener(PauseInputModuleProcess);
            _inputField.onDeselect.AddListener(UnpauseInputModuleProcess);
            ...
        }

        private void PauseInputModuleProcess(string _)
        {
            _inputModule.ProcessPaused = true;
        }

        private void UnpauseInputModuleProcess(string _)
        {
            _inputModule.ProcessPaused = false;
        }

Step 2 - Invoke base.Process() method if processing is paused (MixedRealityInputModule.cs)

        ...

        public override void Process()
        {
            using (ProcessPerfMarker.Auto())
            {
                // Do not process when we are waiting for initialization
                if (ManualInitializationRequired || ProcessPaused)
                {
                    base.Process(); // <--- This line
                    return;
                }

        ...
IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all-new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visit https://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!