public void KeyBindDown(BoundKeyEventArgs args)
        {
            var control = MouseGetControl(args.PointerLocation.Position);

            if (args.CanFocus)
            {
                // If we have a modal open and the mouse down was outside it, close said modal.
                if (_modalStack.Count != 0)
                {
                    var top    = _modalStack[_modalStack.Count - 1];
                    var offset = args.PointerLocation.Position - top.GlobalPixelPosition;
                    if (!top.HasPoint(offset / UIScale))
                    {
                        RemoveModal(top);
                        return;
                    }
                }

                ReleaseKeyboardFocus();

                if (control == null)
                {
                    return;
                }

                _controlFocused = control;

                if (_controlFocused.CanKeyboardFocus && _controlFocused.KeyboardFocusOnClick)
                {
                    _controlFocused.GrabKeyboardFocus();
                }
            }
            else if (KeyboardFocused != null)
            {
                control = KeyboardFocused;
            }

            if (control == null)
            {
                return;
            }

            var guiArgs = new GUIBoundKeyEventArgs(args.Function, args.State, args.PointerLocation, args.CanFocus,
                                                   args.PointerLocation.Position / UIScale - control.GlobalPosition,
                                                   args.PointerLocation.Position - control.GlobalPixelPosition);

            _doGuiInput(control, guiArgs, (c, ev) => c.KeyBindDown(ev));

            if (args.CanFocus)
            {
                args.Handle();
            }
        }
 /// <summary>
 ///     Converts
 /// </summary>
 /// <param name="args">Event data values for a bound key state change.</param>
 private void OnUIKeyBindStateChanged(BoundKeyEventArgs args)
 {
     if (!args.CanFocus && KeyboardFocused != null)
     {
         args.Handle();
     }
     if (args.State == BoundKeyState.Down)
     {
         KeyBindDown(args);
     }
     else
     {
         KeyBindUp(args);
     }
 }
        public void KeyBindUp(BoundKeyEventArgs args)
        {
            var control = _controlFocused ?? KeyboardFocused ?? MouseGetControl(args.PointerLocation.Position);

            if (control == null)
            {
                return;
            }

            var guiArgs = new GUIBoundKeyEventArgs(args.Function, args.State, args.PointerLocation, args.CanFocus,
                                                   args.PointerLocation.Position / UIScale - control.GlobalPosition,
                                                   args.PointerLocation.Position - control.GlobalPixelPosition);

            _doGuiInput(control, guiArgs, (c, ev) => c.KeyBindUp(ev));
            _controlFocused = null;

            // Always mark this as handled.
            // The only case it should not be is if we do not have a control to click on,
            // in which case we never reach this.
            args.Handle();
        }