How do I tell which GUI window currently has focus?

I know you can focus windows using GUI.FocusWindow(int), but how do you know which window currently has focus?

For custom editor windows, you can find the active window by the window title


You can also find if the scene view window has focus by using

if (EditorWindow.focusedWindow == SceneView.currentDrawingSceneView)
    Debug.Log ("'ere");

There may be more than one scene view window open so also check this with


There is no specific "hasFocus" method or function but here is a similar thread and some possible workarounds:

One robust method is to check the class type of the focused window, e.g.:

if (EditorWindow.focusedWindow is UnityEditor.SceneView) {  }