I have an inputField
but when i type in the input field all my “hotkeys” are acting.
Is there a way to disable the keys if input Panel active?
I love to answer my questions:
if (netPanel.activeInHierarchy == false)
I don’t think you can change the behavior of Input.GetKeyUp(), but you can write a script to detect whether an input field is selected, and then you can check that result everywhere you call Input.GetKeyUp() to decide whether to accept or ignore the input.
It might look something like this:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using TMPro;
public class DetectKeyboardActive : MonoBehaviour
{
EventSystem system;
public bool inputFieldSelected;
void OnEnable()
{
system = EventSystem.current;
}
void Update()
{
inputFieldSelected = false;
if (system == null)
{
system = EventSystem.current;
if (system == null) return;
}
GameObject currentObject = system.currentSelectedGameObject;
if (currentObject != null)
{
InputField inputField = currentObject.GetComponent<InputField>();
if (inputField != null)
{
inputFieldSelected = true;
}
else
{
TMP_InputField tmpInput = currentObject.GetComponent<TMP_InputField>();
if (tmpInput != null)
{
inputFieldSelected = true;
}
}
}
}
}
You can remove the TMP stuff if you’re not using TextMeshPro.
Sorry i was faster and it works
Your solution from comment #2 will disable your hotkeys even if the input field is active but not in focus or being typed into. Checking InputField.isFocused is probably better.
https://docs.unity3d.com/ScriptReference/UI.InputField-isFocused.html
Can you tell me what exactly is the difference between being selected and being focused?
I don’t know if there is a difference. Just there doesn’t appear to be an isSelected bool to check according to the docs.