From c8bb190c2e3d269d87ed08d98edfc124a0ce8702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Wed, 17 Dec 2025 13:04:58 +0800 Subject: [PATCH] fix --- Runtime/Input/InputDeviceWatcher.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Runtime/Input/InputDeviceWatcher.cs b/Runtime/Input/InputDeviceWatcher.cs index cf50c8a..2aee144 100644 --- a/Runtime/Input/InputDeviceWatcher.cs +++ b/Runtime/Input/InputDeviceWatcher.cs @@ -42,7 +42,6 @@ public static class InputDeviceWatcher _anyInputAction = new InputAction("AnyDevice", InputActionType.PassThrough); _anyInputAction.AddBinding("/anyKey"); - _anyInputAction.AddBinding("/*"); _anyInputAction.AddBinding("/*"); _anyInputAction.AddBinding("/*"); @@ -88,6 +87,9 @@ public static class InputDeviceWatcher if (ctx.control == null || ctx.control.device == null) return; var device = ctx.control.device; + + if (!IsRelevantDevice(device)) return; + int curId = device.deviceId; float now = Time.realtimeSinceStartup; @@ -123,7 +125,9 @@ public static class InputDeviceWatcher private static InputDeviceCategory DetermineCategoryFromDevice(InputDevice device) { if (device == null) return InputDeviceCategory.Keyboard; - if (device is Keyboard || device is Mouse) return InputDeviceCategory.Keyboard; + // 重要:鼠标不再被视为键盘类(避免鼠标触发时回退到 Keyboard) + if (device is Keyboard) return InputDeviceCategory.Keyboard; + if (device is Mouse) return InputDeviceCategory.Other; // 明确忽略鼠标 if (IsGamepadLike(device)) return GetGamepadCategory(device); string combined = $"{device.description.interfaceName} {device.layout} {device.description.product} {device.description.manufacturer} {device.displayName}".ToLower(); @@ -140,9 +144,19 @@ public static class InputDeviceWatcher if (device is Joystick) return true; var layout = (device.layout ?? "").ToLower(); + // 这里保留 controller/gamepad/joystick 的识别,但忽略 mouse/touch 等 + if (layout.Contains("mouse") || layout.Contains("touch") || layout.Contains("pen")) return false; return layout.Contains("gamepad") || layout.Contains("controller") || layout.Contains("joystick"); } + private static bool IsRelevantDevice(InputDevice device) + { + if (device == null) return false; + if (device is Keyboard) return true; + if (IsGamepadLike(device)) return true; + return false; + } + private static InputDeviceCategory GetGamepadCategory(InputDevice device) { if (device == null) return InputDeviceCategory.Other; @@ -186,7 +200,6 @@ public static class InputDeviceWatcher } } - // ------------------ 输出 -------------------- private static void EmitChange() { if (CurrentCategory == _lastEmittedCategory) @@ -201,7 +214,6 @@ public static class InputDeviceWatcher Debug.Log($"输入设备变更 -> {CurrentCategory} 触发设备: {CurrentDeviceName} vid=0x{vid:X} pid=0x{pid:X}"); #endif - // 触发事件并记录已发射的分类 OnDeviceChanged?.Invoke(CurrentCategory); _lastEmittedCategory = CurrentCategory; }