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?