Help with Editor Script

I have this script:

using UnityEngine;
using UnityEditor;

public class FocusGameView : EditorWindow
{
    [MenuItem("Hotkeys/Focus Game View %w")] // &w represents the hotkey Ctrl+W on Windows, Cmd+W on macOS
    private static void FocusOnGameView()
    {
      
        if (UnityEditor.EditorWindow.focusedWindow.ToString() != " (UnityEditor.GameView)" )
        {

            Debug.LogWarning("focusing to game view");
            FocusWindowIfItsOpen(typeof(EditorWindow).Assembly.GetType("UnityEditor.GameView"));


        }

    }
}

it works well, its a script that focuses on the game window when I press “ctrl+W”

however now I have a problem, after focusing I have this call in another script:

    if (Input.GetKeyUp(KeyCode.LeftControl))
        {
            ctrlCurrentlyPressed = false;
        }

So when I hold ctrl + W, the focus comes back to the game view, but I then release the ctrl key the release call is not getting detected.

Only after i release ctrl, press it again and release it again does it go back to normal

This seems like its a symptom from changing the focus back to game while the ctrl key is currently pressed, when its depressed its not getting detected

Its odd, because if I switch focus manually with a mouse click this behaviour does not occur

You can observe the same behaviour if you use the normal hotkey to switch to the game view (ctrl+2), when you release the ctrl key it wont get detected by input.getkeyup

If someone could help me I would appreciate it, how do I make it so that releasing the ctrl key gets detected after refocusing the gameview trough script?

This is deliberate behavior and usually what you want. E.g. if you have a shortcut that triggers Unity entering play mode, you don’t want that shortcut to then trigger something in the game if you keep holding it. This is why you first need a down before you can get an up.

In the new input system, this behavior can be configured (it’s off for Value action types and for Button action types you can enable “Initial State Check”). I don’t think there’s an equivalent option for the old input manager.

Does Input.GetKey also return false? If it doesn’t you could implement the up checking by yourself.

yes, I found initially that getkey was not returning true

my workaround for that would be to force a bool to true through the editor script, to emulate the key starting as pressed, my conundrum is now how can I turn it back to false if the input.getkeyUp is not getting detected