Search Unity

Question How to get keyboard input in SceneView?

Discussion in 'Editor & General Support' started by Rowlan, Aug 20, 2021.

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,270
    When you are in the inspector and move the mouse to the sceneview, the mouse as well as the modifier keys get recognized. But none of the other keys. Well, unless you click on the sceneview and it gets the focus.

    Does anyone have a solution to that yet? I searched and the only solution I've found so far is to use ClutchShortcutAttribute, basically something like this:

    Code (CSharp):
    1. using UnityEditor.ShortcutManagement;
    2. using UnityEngine;
    3.  
    4. public class Example : MonoBehaviour
    5. {
    6.     [ClutchShortcutAttribute("MyContext/MyFunction", null, KeyCode.Y, ShortcutModifiers.Shift)]
    7.     private static void ShortcutTest( ShortcutArguments args)
    8.     {
    9.         if (args.stage == ShortcutStage.Begin)
    10.         {
    11.             Debug.Log("Key Down");
    12.         }
    13.         else if (args.stage == ShortcutStage.End)
    14.         {
    15.             Debug.Log("Key Up");
    16.         }
    17.     }
    18. }
    19.  
    However, the above "null" should be the context of my gameobject which has the editor script attached. So that doesn't work either and I really don't want to have a global context. Is there a proper solution to getting keyboard input without having to click on the sceneview first?
     
    awesomedata and jorikito like this.