Getting key input to ignore when a player is typing in an input box.

The title says it all, basically I have a developer console and if I type in it, I can still walk for example if I press W or any other keys that control my menu UI.

If the menu is enabled set a flag. In your player code, skip the key checks if the menu flag is true.

Yeah that’s what I figured, thanks.

Edit: Just did it based on whether the cursor was visible or not as I have a toggle for that and it toggles automatically when a menu opens :wink:

In the former UI system, all the input typed in an input text field were ignore, it was a really handy behavior.
Too bad this doesn’t came out with the new ui system. At least choosing wether or not we want this behaviour would be great.

Vote for this feature here : http://feedback.unity3d.com/suggestions/ignore-key-input-while-typing-in-an-inputfield

You can check like this (Not very performant if you have a lot of selectables in the scene):

    private static bool IsPointerFocusedInputField()
    {

        var selectables = Selectable.allSelectables;
        foreach (var selectable in selectables)
        {
            var inputField = selectable as InputField;
            if (inputField && inputField.isFocused)
            {
                return true;
            }
        }
        return false;
    }
1 Like

@ibrahimpenekli 's method works, thanks for that.

I came here however looking to know when any UI element has foucs, i.e. is selected. This is because I need to prevent mouse click-and-drag from rotating my scene view when the user is actually adjusting a slide. My UI is always up and I don’t want to add handlers to every control to track when the mouse enters and exits.

So this simple check works well for anyone else coming here for the same reasons as I

    private bool IsUIactive()
    {
        return EventSystem.current.currentSelectedGameObject != null;
    }