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

EditorWindow.focusedWindow.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

SceneView.sceneViews.Count

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

http://forum.unity3d.com/viewtopic.php?p=125931&sid=326d6eea72706e6216e73ca6904c2774

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

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