- Home /
adding input combinations to a custom editor script?
Basically, I am trying to add in a 'Ctrl + Scrollwheel' input to change a variable up for a positive scroll or down for a negative scroll in an editor script that i am creating.
What is the best way to approach this input combination for the editor?
Everything i have looked up mostly refers to adding a Ctrl activation to a menu item and this is not what i am looking for.
~EDIT~
Upon further searching, i have stumbled upon code references that may be useful, but i can't seem to get them to work to do what i need. There is a bool variable named 'modifier' declared with the other variables as well one called inc which i am using to try and limit the scroll wheel to only one call per scroll.
Event e = Event.current;
if (e.isScrollWheel && e.control) {
if (e.delta.y == 3 && inc)
{
Debug.Log(e.delta.y);
selectedPrefabNum -= 1;
inc = false;
}
else if (e.delta.y == -3 && inc)
{
Debug.Log(e.delta.y);
selectedPrefabNum += 1;
inc = false;
}
}
Answer by Bunny83 · Aug 02, 2017 at 05:45 AM
The Event class always hold the state of the 3 modifier keys: alt, control and shift.
So there's no need to track the modifier state yourself. However if you do, you have to react to the KeyDown and KeyUp events
switch (e.type)
{
case EventType.KeyDown:
{
if (Event.current.keyCode == KeyCode.LeftControl)
modifier = true;
}
break;
case EventType.KeyUp:
{
if (Event.current.keyCode == KeyCode.LeftControl)
modifier = false;
}
break;
// ...
i fixed this, but im noticing i can only get the event to fire once ive clicked on my window of the extension. is there any way to track the events globally? or at least when im in the editor? and on top of that, my scrolling is still not being detected using delta it seems.
Events are generally send to the active window. If you focus another window, that window will receive all events. There is no real solution to get events globally. It also wouldn't make much sense. All user interactions are always context specific. If you want to react to events in the SceneView, you can subscribe a callback to the "SceneView.onSceneGUIDelegate". If you need to react to events in the inspector that can only be done from an active custom inspector.
$$anonymous$$eep in $$anonymous$$d that the scrollwheel is used for many other things as well. Reacting globally to such an event wouldn't make much sense. For example the animation editor window uses Shift-scroll and Control-scroll for scaling horizontally / vertically.
yeah i was going to add the alt modifier to my scroll so its Ctrl+Alt+Scroll to avoid most of the scrolling inputs, but i mainly need it in the scene view. I'm creating the ability to scroll through the currently loaded assets to switch between them instantly. I'm looking into the SceneView.onSceneGUIDelegate, thank you. once i know this is what I'm looking for, ill accept your answer :)
Your answer
Follow this Question
Related Questions
Removing Inputs from the Input list 1 Answer
Detect input from EditorApplication.update callback? 1 Answer
How to detect if project is Using new or Old Input System via code? 1 Answer
Override scene view grid with my own? 0 Answers
Make custom input devices available to scripting via "Input" 2 Answers