Scene view script input question.

Hi, I’ve been searching around and testing things for a while and can’t seem to catch any keys pressed from the scene view in my script.

In javascipt in the *assets/editor folder I have my script with just the following:

function OnSceneGUI () {
	if (Event.current.keyCode == KeyCode.Keypad0) {
		print("Evil Laugh!");
	}
}

Can anyone help please?

I got something working but its seem like alot of work just to get the input working in scene view. Thanks to someone on the forums for this C# script:

using UnityEditor;
using UnityEngine;

public class ForSceneViewInput : EditorWindow
{
	private static ForSceneViewInput window = null;
	SceneView.OnSceneFunc onSceneGUIFunc = null;

	[MenuItem("Tools/ForSceneViewInput")]
	static void Init()
	{
		if (window == null)
		{
			window = EditorWindow.GetWindow<ForSceneViewInput >(false, "ForSceneViewInput", true);
			window.onSceneGUIFunc = new SceneView.OnSceneFunc(OnSceneGUI);
			SceneView.onSceneGUIDelegate += window.onSceneGUIFunc;
		}
	}

	void OnDestroy()
	{
		SceneView.onSceneGUIDelegate -= onSceneGUIFunc;
		window = null;
	}

	public static void OnSceneGUI(SceneView sceneview)
	{
		if (Event.current.keyCode == KeyCode.Keypad0) {
			GameObject go2 = new GameObject ("test");
		}
		if (Event.current.keyCode == KeyCode.KeypadPeriod) {
			GameObject go1 = new GameObject ("test2");
		}
	}
}

You can see where i get the keycode events. Thats the part you may want to modify. I couldn’t seem to add a variable for a separate script at that part, I think its unsupported by OnSceneGUI (I used temporary objects instead and just deleted them after I detected them and ran “key down” code because they were found).

To use it just copy into a new C# script, put it in the right folder (if needed to compile before/after other scripts, mine is in assets/plugins), edit events and what happens when triggered (if you want), save, go to tools at top and run ForSceneViewInput, grab tab and dock (if needed/wanted), go back to your normal scene view and you should have your new triggers. :sunglasses: