From 24e87758b105f77a791c751dfd82d60f866f542b Mon Sep 17 00:00:00 2001 From: sergey-cs Date: Sat, 16 Nov 2024 15:44:08 +0300 Subject: [PATCH] fix-exception-when-keyboard-is-not-connected --- Assets/EasyTab/Source/EasyTabInput.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Assets/EasyTab/Source/EasyTabInput.cs b/Assets/EasyTab/Source/EasyTabInput.cs index c900a78..ae67143 100644 --- a/Assets/EasyTab/Source/EasyTabInput.cs +++ b/Assets/EasyTab/Source/EasyTabInput.cs @@ -12,13 +12,25 @@ public class EasyTabInput public void GetInput(out float tabPressedTime, out bool isShiftPressed, out bool isEnterPressed) { + bool tabPressed; + #if ENABLE_INPUT_SYSTEM - var tabPressed = Keyboard.current.tabKey.isPressed; - isShiftPressed = Keyboard.current.shiftKey.isPressed; - isEnterPressed = Keyboard.current.enterKey.wasPressedThisFrame || - Keyboard.current.numpadEnterKey.wasPressedThisFrame; + var keyboard = Keyboard.current; + if (keyboard != null) + { + tabPressed = keyboard.tabKey.isPressed; + isShiftPressed = keyboard.shiftKey.isPressed; + isEnterPressed = keyboard.enterKey.wasPressedThisFrame || + keyboard.numpadEnterKey.wasPressedThisFrame; + } + else // if not keyboard. like PS5. https://github.com/dav-sea/EasyTab/issues/7 + { + tabPressed = false; + isShiftPressed = false; + isEnterPressed = false; + } #else - var tabPressed = Input.GetKey(KeyCode.Tab); + tabPressed = Input.GetKey(KeyCode.Tab); isShiftPressed = Input.GetKey(KeyCode.LeftShift); isEnterPressed = Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter); #endif