- Home /
Question by
MWahnish · Sep 30, 2014 at 04:26 AM ·
editoreditor extensionevent-handling
Intercepting Delete key event in editor
I'm putting together an editor extension and I need to call some code when the delete key is pressed. Unfortunately, the Unity editor is catching that event before it reaches my code. Here is what I have so far:
[CustomEditor(typeof(MyObject))]
public class MyObjectEditor : Editor {
public void OnSceneGUI() {
if (Event.current != null &&
Event.current.isKey &&
Event.current.type.Equals(EventType.keyDown) &&
Event.current.keyCode == KeyCode.Delete) {
//Delete code here
}
}
}
Anyone know any tricks?
Comment
Best Answer
Answer by BenKurdziel · Oct 02, 2014 at 12:46 AM
Have you tried either of the following?
GUIUtility.hotControl = 0;
Event.current.Use();
The idea is that GUIUtility.hotControl removes the focus from whatever is selected, and Event.current.Use() "eats" the event so that it doesn't make it to the sceneview.
Sorry for the wait! Was on travel. Event.current.Use() did the trick. Thanks!
Thanks! In my case, using GUIUtility.hotControl = 0
was unnecessary. Event.current.Use()
indeed did the trick