private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         OnEscapePressed?.Invoke();
     }
 }
        private void HandleKeyboard()
        {
            Event evt = Event.current;

            if (evt.type == EventType.KeyDown)
            {
                // Always do these
                if (evt.keyCode == KeyCode.DownArrow)
                {
                    activeParent.selectedIndex++;
                    activeParent.selectedIndex = Mathf.Min(activeParent.selectedIndex, GetChildren(activeTree, activeParent).Count - 1);
                    m_ScrollToSelected         = true;
                    evt.Use();
                }
                if (evt.keyCode == KeyCode.UpArrow)
                {
                    activeParent.selectedIndex--;
                    activeParent.selectedIndex = Mathf.Max(activeParent.selectedIndex, activeParent.element?.Children.Any(c => c.IsWarning) ?? false ? 1 : 0);
                    m_ScrollToSelected         = true;
                    evt.Use();
                }
                if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter)
                {
                    GoToChild(activeElement, true);
                    evt.Use();
                }

                // Do these if we're not in search mode
                if (!hasSearch)
                {
                    if (evt.keyCode == KeyCode.LeftArrow || evt.keyCode == KeyCode.Backspace)
                    {
                        GoToParent();
                        evt.Use();
                    }
                    if (evt.keyCode == KeyCode.RightArrow)
                    {
                        if (activeElement is GroupElement)
                        {
                            GoToChild(activeElement, false);
                        }

                        evt.Use();
                    }
                    if (evt.keyCode == KeyCode.Escape)
                    {
                        GUIUtility.keyboardControl = 0;
                        OnEscapePressed.Invoke();
                        evt.Use();
                    }
                }
            }
        }
Exemple #3
0
        private static IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case WmHotkey:
                switch (wParam.ToInt32())
                {
                case HotkeyId:
                    OnHotkeyPressed?.Invoke();
                    handled = true;
                    break;

                case EscapeHotkeyId:
                    OnEscapePressed?.Invoke();
                    handled = true;
                    break;
                }
                break;
            }
            return(IntPtr.Zero);
        }
Exemple #4
0
 private void OnKeyPressed(object sender, KeyEventArgs e)
 {
     if (started)
     {
         if (stop == 0)
         {
             if (e.Code == Keyboard.Key.W)
             {
                 if (!up)
                 {
                     _updateY += -1;
                     up        = true;
                 }
             }
             else if (e.Code == Keyboard.Key.S)
             {
                 if (!down)
                 {
                     _updateY += 1;
                     down      = true;
                 }
             }
             else if (e.Code == Keyboard.Key.A)
             {
                 if (!left)
                 {
                     _updateX += -1;
                     left      = true;
                 }
             }
             else if (e.Code == Keyboard.Key.D)
             {
                 if (!right)
                 {
                     _updateX += 1;
                     right     = true;
                 }
             }
             else if (e.Code == Keyboard.Key.R)
             {
                 roundOver = !roundOver;
             }
         }
         if (roundOver)
         {
             if (e.Code == Keyboard.Key.E)
             {
                 if (stop == 0)
                 {
                     stop     = 2;
                     _updateX = 0;
                     _updateY = 0;
                     up       = false;
                     down     = false;
                     left     = false;
                     right    = false;
                     OnEPressed?.Invoke();
                 }
                 else if (stop == 2)
                 {
                     stop = 0;
                     OnEPressed?.Invoke();
                 }
             }
             else if (e.Code == Keyboard.Key.Escape)
             {
                 if (stop == 0)
                 {
                     stop     = 1;
                     _updateX = 0;
                     _updateY = 0;
                     up       = false;
                     down     = false;
                     left     = false;
                     right    = false;
                     OnEscapePressed?.Invoke();
                 }
                 else if (stop == 1)
                 {
                     stop = 0;
                     OnEscapePressed?.Invoke();
                 }
                 else if (stop == 2)
                 {
                     stop = 0;
                     OnEPressed?.Invoke();
                 }
             }
         }
         else if (!roundOver)
         {
             if (e.Code == Keyboard.Key.Space)
             {
                 if (stop == 0)
                 {
                     stop     = 3;
                     _updateX = 0;
                     _updateY = 0;
                     up       = false;
                     down     = false;
                     left     = false;
                     right    = false;
                     OnSpacePressed?.Invoke();
                 }
                 else if (stop == 3)
                 {
                     stop = 0;
                     OnSpacePressed?.Invoke();
                 }
             }
         }
     }
 }