Suppress global hotkeys while a text field is focused
The save-dialog name field is a focused TMP_InputField, but global discrete hotkeys kept reading the keyboard every frame, so typing a name like "Checkers" cycled the pose (C) and shut the server down (K). Add a shared TypingGuard.IsTyping check (focused TMP/legacy InputField) and short-circuit the global handlers on it: pose cycle, network dev keys, mode switch, and paint undo/redo. Movement was already gated out via ControlEnabled. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b951556f35
commit
5965f7199a
6 files changed
+36
No files matched your search
@@ -347,6 +347,7 @@ public class GameModeManager : MonoBehaviour
|
||||
|
||||
private bool WasSwitchPressed()
|
||||
{
|
||||
if (TypingGuard.IsTyping) return false; // don't switch modes while typing in a text field
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return Keyboard.current != null && Keyboard.current[switchKey].wasPressedThisFrame;
|
||||
#else
|
||||
|
||||
@@ -241,6 +241,7 @@ public partial class MeshPainter
|
||||
{
|
||||
undo = false;
|
||||
redo = false;
|
||||
if (TypingGuard.IsTyping) return; // let Ctrl+Z/Y edit text instead of the painting
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var kb = Keyboard.current;
|
||||
if (kb != null)
|
||||
|
||||
@@ -38,6 +38,7 @@ public class NetworkBootstrap : MonoBehaviour
|
||||
private void Update()
|
||||
{
|
||||
if (!enableHotkeys) return;
|
||||
if (TypingGuard.IsTyping) return; // don't fire H/C/J/K while typing in a text field
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var kb = Keyboard.current;
|
||||
if (kb == null || _net == null) return;
|
||||
|
||||
@@ -341,6 +341,7 @@ public class PlayerPoseController : MonoBehaviour
|
||||
|
||||
private bool CycleKeyPressed()
|
||||
{
|
||||
if (TypingGuard.IsTyping) return false; // don't cycle pose while typing in a text field
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var keyboard = Keyboard.current;
|
||||
return keyboard != null && keyboard[cycleKey].wasPressedThisFrame;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
/// <summary>
|
||||
/// True while the user is editing a focused on-screen text field (e.g. the paint HUD's
|
||||
/// "save as" name input). Global gameplay/dev hotkeys consult this so typing a name like
|
||||
/// "Checkers" doesn't also fire single-key shortcuts (C = cycle pose, K = shutdown,
|
||||
/// the mode-switch key, Ctrl+Z = undo, ...).
|
||||
/// </summary>
|
||||
public static class TypingGuard
|
||||
{
|
||||
/// <summary>A text input field is currently focused and capturing keystrokes.</summary>
|
||||
public static bool IsTyping
|
||||
{
|
||||
get
|
||||
{
|
||||
var es = EventSystem.current;
|
||||
if (!es) return false;
|
||||
|
||||
var go = es.currentSelectedGameObject;
|
||||
if (!go) return false;
|
||||
|
||||
var tmp = go.GetComponent<TMP_InputField>();
|
||||
if (tmp) return tmp.isFocused;
|
||||
|
||||
var legacy = go.GetComponent<UnityEngine.UI.InputField>();
|
||||
return legacy && legacy.isFocused;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c30f56f99c2725a4e861c19a5e83e0aa
|
||||
Reference in new issue
Block a user