I am writing an editor script and I want to be able to check if a key is or has been pressed regardless of what has focus. I realize that Input won’t work. So far I haven’t been able to find anything in the documentation or on Google that would allow me to do this. I was wondering how to do this or if it is even possible.
[CustomEditor(typeof(yourClassTarget))]
public class yourEditorClass: Editor
{
void OnSceneGUI()
{
VertexPaint script = (VertexPaint)target;
Event e = Event.current;
switch (e.type)
{
case EventType.keyDown:
{
if (Event.current.keyCode == (KeyCode.A))
{
script.Painting = true;
}
break;
}
}
}
}
I know that this post is archeology, but to complete the exemple code of the answer you have to add the instruction e.Use(); after your code.
[CustomEditor(typeof(yourClassTarget))]
public class yourEditorClass: Editor
{
void OnSceneGUI()
{
VertexPaint script = (VertexPaint)target;
Event e = Event.current;
switch (e.type)
{
case EventType.keyDown:
{
if (Event.current.keyCode == (KeyCode.A))
{
script.Painting = true;
// EDIT : this a the instruction to add.
// You realy need it to avoid performance issues !
e.Use();
// END EDIT
}
break;
}
}
}
}