- Home /
Key Events in Hierarchy Window
I know its possible to detect key events when the inspector window is selected, using a custom editor. ie:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(MyClass))]
public class MyClassEditor: Editor
{
public override void OnInspectorGUI()
{
// Draw Default Inspector
DrawDefaultInspector();
// Respond to key presses
if (Event.current.isKey)
{
Debug.Log("Key Pressed- lets do something!");
}
}
}
But is there a way to do this when the Hiearchy Window is in focus?
Answer by sotirosn · Nov 21, 2013 at 09:31 PM
I don't think OnInspectorGUI captures events. And the hierarchy window is not the same as the inspector window so your title is wrong.
The title is correct, but maybe the question could have been worded more clearly?
The Inspector does capture keyboard events when its in focus. The code listed is an example of a custom inspector for the "$$anonymous$$yClass" $$anonymous$$onoBehavior that captures keyboard events. If you put the $$anonymous$$yClass script on an object, select the object, click on the inspector, and press a key, it will bring the statement to the debug log.
What I as asking is if there is a similar mechanism for doing this when selecting objects in the Hierarchy Window. So, for example, I could select an object from the hierarchy and press a key to do some custom logic on the event.
Hmm I need the same thing actually because I would like to respond to when objects are duplicated or copy/pasted. You can hook the inspector and scene view but I don't think the hierarchy. $$anonymous$$aybe you can derive the EditorWindow class and make your own hierarchy window?
This post might help you, though its not exactly what we're proposing here, as you still need to have the Inspector selected. http://forum.unity3d.com/threads/94007-Detecting-Copy-Paste-Duplicate-Events-on-Editor
Your answer
Follow this Question
Related Questions
How to force close Popup Window? 1 Answer
How do I change inspector values of other game objects using a custom Editor Window 0 Answers
Getting a target's gameobject in custom editor 1 Answer
Prefabs aren't saving with Undo.RecordObject 4 Answers
Inspector: custom property with custom type use default editor 3 Answers