I’m doing an EditorWindow inherited class, and I need User input such as arrow keys pressed at any time.
Knowing OnGUI() can only listen to Event.current.isKey for such input, I’m using that (though I’d rather not since it causes issues with window must have focus)
I’ve crossed quite a lot of sync-barriers by placing
if (Event.current != null && Event.current.isKey)
{
Repaint();
}
at the top of
void OnGUI()
… However one thing I struggle with, is that apparently since there’s no input field Unity is returning an system error beep every time a key is pressed.
At least on Mac, have not even tried on Win yet, but even on one platform it’s a drag, I’d really like my Editor script not to inform the user he’s doing something wrong when he’s not
Would you know how to ‘catch’ the input (like it’s done in input fields) so no error sounds are returned… or even better; A (hack) to not rely on Event.current.isKey for user input in EditorWindow?
I don’t see that behaviour on Windows. Maybe it’s a Mac specific issue…
Have you actually tried “eating” the event?
Event.current.Use();
btw: You don’t have to check if Event.current is null. OnGUI is only called when an event is set. Also keep in mind there are several “key” events that might fire for a single key. You always get at least a key down and a key up. “isKey” is just a shorthand for testing if the current event type is one of the key messages.
EditorWindows can also handle events inside the sceneview. For that you can subscribe a method to the static event SceneView.onSceneGUIDelegate.
But since we have no idea what’s the point of your editor window, suggesting things it kind of pointless ^^.