Since I am automatically docking my editor window to the Scene View Type, and would prefer to have this part of the application this way, the problem I face is that the only way I know to listen to keys in an editor window is to use Event.current and delegating a function with SceneView.duringSceneGUI. Since my window is docked along with my Scene and Game windows SceneView will not be executing this.
Does anyone know how to listen for key input without SceneView? I’ve had a hard time finding any resources for this online.
This is what I mean by auto-docking to SceneView.
Type sceneType = Type.GetType("UnityEditor.SceneView,UnityEditor.dll");
customWindow window = (CustomWindow)EditorWindow.GetWindow<CustomWindow>("Custom Window", new Type[] { sceneType });
Well, events are always only send to the active window, no matter what that might be. So if the inspector is active, the inspector will receive the input, if the sceneview is active, the scene view will receive the input and when your own custom editor window is active, it will receive the input.
It’s not really clear what you actually want to do. As I said you can process any kind of events inside your editor window when your window is active / has the focus. If you’re asking if it’s possible to intercept input regardless of the focussed window, the answer is: No, not by any “normal” approach. It’s the same across your operating system. Keyboard input is only send to the active / focussed application. The operating system may provide means like hotkeys or low level keyboard hooks, but they are really only used in very rare cases.
It’s possible to implement an operating system specific solution for capturing keyboard input either application wide or system wide. However as I said in almost all cases you don’t want such behaviour.
if (Keyboard.current.gKey.wasPressedThisFrame)
{
Debug.Log(" g was pressed this frame");
}
Not sure if this is what you’re after, Keyboard.current.“some key”.wasPressedThisFrame seems to listen to keyboard input regardless of what current editor window has focus.