From d4451d6e3b55336103fb662fda090d5d8384d7e4 Mon Sep 17 00:00:00 2001 From: Nicholas Karr Date: Tue, 30 May 2023 14:27:38 -0500 Subject: [PATCH] Disable keyboard navigation while typing (#396) --- Assets/Script/Input/InputStrategy.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Assets/Script/Input/InputStrategy.cs b/Assets/Script/Input/InputStrategy.cs index 5706dfe58..74186e6bf 100644 --- a/Assets/Script/Input/InputStrategy.cs +++ b/Assets/Script/Input/InputStrategy.cs @@ -1,6 +1,9 @@ using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Linq; using PlasticBand.Haptics; +using TMPro; +using UnityEngine.EventSystems; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.LowLevel; @@ -186,9 +189,17 @@ private void OnInputEvent(InputEventPtr eventPtr) { // Only take state events if (!eventPtr.IsA() && !eventPtr.IsA()) { return; - } - - // Update mapping states + } + + // Ignore navigation events from the keyboard while a text box is selected + // We detect whether a text box is selected by seeing if a focused input field is a component of the currently selected object + if (eventPtr.deviceId == Keyboard.current.deviceId && + (EventSystem.current.currentSelectedGameObject?.GetComponents().Any(i => i.isFocused) ?? false)) { + + return; + } + + // Update mapping states foreach (var mapping in inputMappings.Values) { mapping.UpdateState(eventPtr); }