Example #1
0
        protected override bool Handle(UIEvent e)
        {
            var state = e.CurrentState;

            switch (e)
            {
            case MouseDownEvent mouseDown:
                return(handleNewPressed(state, KeyCombination.FromMouseButton(mouseDown.Button), false));

            case MouseUpEvent mouseUp:
                handleNewReleased(state, KeyCombination.FromMouseButton(mouseUp.Button));
                return(false);

            case KeyDownEvent keyDown:
                if (keyDown.Repeat && !SendRepeats)
                {
                    return(pressedBindings.Count > 0);
                }

                if (handleNewPressed(state, KeyCombination.FromKey(keyDown.Key), keyDown.Repeat))
                {
                    return(true);
                }

                return(false);

            case KeyUpEvent keyUp:
                handleNewReleased(state, KeyCombination.FromKey(keyUp.Key));
                return(false);

            case JoystickPressEvent joystickPress:
                return(handleNewPressed(state, KeyCombination.FromJoystickButton(joystickPress.Button), false));

            case JoystickReleaseEvent joystickRelease:
                handleNewReleased(state, KeyCombination.FromJoystickButton(joystickRelease.Button));
                return(false);

            case MidiDownEvent midiDown:
                return(handleNewPressed(state, KeyCombination.FromMidiKey(midiDown.Key), false));

            case MidiUpEvent midiUp:
                handleNewReleased(state, KeyCombination.FromMidiKey(midiUp.Key));
                return(false);

            case TabletPenButtonPressEvent tabletPenButtonPress:
                return(handleNewPressed(state, KeyCombination.FromTabletPenButton(tabletPenButtonPress.Button), false));

            case TabletPenButtonReleaseEvent tabletPenButtonRelease:
                handleNewReleased(state, KeyCombination.FromTabletPenButton(tabletPenButtonRelease.Button));
                return(false);

            case TabletAuxiliaryButtonPressEvent tabletAuxiliaryButtonPress:
                return(handleNewPressed(state, KeyCombination.FromTabletAuxiliaryButton(tabletAuxiliaryButtonPress.Button), false));

            case TabletAuxiliaryButtonReleaseEvent tabletAuxiliaryButtonRelease:
                handleNewReleased(state, KeyCombination.FromTabletAuxiliaryButton(tabletAuxiliaryButtonRelease.Button));
                return(false);

            case ScrollEvent scroll:
            {
                var  keys    = KeyCombination.FromScrollDelta(scroll.ScrollDelta);
                bool handled = false;

                foreach (var key in keys)
                {
                    handled |= handleNewPressed(state, key, false, scroll.ScrollDelta, scroll.IsPrecise);
                    handleNewReleased(state, key);
                }

                return(handled);
            }
            }

            return(false);
        }
        protected override bool Handle(UIEvent e)
        {
            var state = e.CurrentState;

            switch (e)
            {
            case MouseDownEvent mouseDown:
                return(handleNewPressed(state, KeyCombination.FromMouseButton(mouseDown.Button), false));

            case MouseUpEvent mouseUp:
                handleNewReleased(state, KeyCombination.FromMouseButton(mouseUp.Button));
                return(false);

            case KeyDownEvent keyDown:
                if (keyDown.Repeat && !SendRepeats)
                {
                    return(pressedBindings.Count > 0);
                }

                foreach (var key in KeyCombination.FromKey(keyDown.Key))
                {
                    if (handleNewPressed(state, key, keyDown.Repeat))
                    {
                        return(true);
                    }
                }

                return(false);

            case KeyUpEvent keyUp:
                // this is releasing the common shift when a remaining shift is still held.
                // ie. press LShift, press RShift, release RShift will result in InputKey.Shift being incorrectly released.
                foreach (var key in KeyCombination.FromKey(keyUp.Key))
                {
                    handleNewReleased(state, key);
                }

                return(false);

            case JoystickPressEvent joystickPress:
                return(handleNewPressed(state, KeyCombination.FromJoystickButton(joystickPress.Button), false));

            case JoystickReleaseEvent joystickRelease:
                handleNewReleased(state, KeyCombination.FromJoystickButton(joystickRelease.Button));
                return(false);

            case MidiDownEvent midiDown:
                return(handleNewPressed(state, KeyCombination.FromMidiKey(midiDown.Key), false));

            case MidiUpEvent midiUp:
                handleNewReleased(state, KeyCombination.FromMidiKey(midiUp.Key));
                return(false);

            case TabletPenButtonPressEvent tabletPenButtonPress:
                return(handleNewPressed(state, KeyCombination.FromTabletPenButton(tabletPenButtonPress.Button), false));

            case TabletPenButtonReleaseEvent tabletPenButtonRelease:
                handleNewReleased(state, KeyCombination.FromTabletPenButton(tabletPenButtonRelease.Button));
                return(false);

            case TabletAuxiliaryButtonPressEvent tabletAuxiliaryButtonPress:
                return(handleNewPressed(state, KeyCombination.FromTabletAuxiliaryButton(tabletAuxiliaryButtonPress.Button), false));

            case TabletAuxiliaryButtonReleaseEvent tabletAuxiliaryButtonRelease:
                handleNewReleased(state, KeyCombination.FromTabletAuxiliaryButton(tabletAuxiliaryButtonRelease.Button));
                return(false);

            case ScrollEvent scroll:
            {
                var  keys    = KeyCombination.FromScrollDelta(scroll.ScrollDelta);
                bool handled = false;

                foreach (var key in keys)
                {
                    handled |= handleNewPressed(state, key, false, scroll.ScrollDelta, scroll.IsPrecise);
                    handleNewReleased(state, key);
                }

                return(handled);
            }
            }

            return(false);
        }