public bool CheckIfMatches(InputControlSelection hotkey, Keys keyPressed)
 {
     return((hotkey != null) && hotkey.ControlType == ControlType.Key &&
            (
                (hotkey.Keys & Keys.KeyCode) == (keyPressed & Keys.KeyCode)
                &&
                (hotkey.Keys & Keys.Modifiers) == (keyPressed & Keys.Modifiers)
            ));
 }
Пример #2
0
        public bool DirectInputHotkeyIsTriggering(InputControlSelection hotkey)
        {
            if (hotkey == null || hotkey.DirectInputControl == null)
            {
                return(false);
            }
            int?currentVal = _mediator.GetPhysicalControlValue(hotkey.DirectInputControl, StateType.Current);
            int?prevVal    = _mediator.GetPhysicalControlValue(hotkey.DirectInputControl, StateType.Previous);

            switch (hotkey.ControlType)
            {
            case ControlType.Unknown:
                break;

            case ControlType.Axis:
                if (currentVal.HasValue && !prevVal.HasValue)
                {
                    return(true);
                }
                if (!currentVal.HasValue && prevVal.HasValue)
                {
                    return(true);
                }
                return(currentVal.Value != prevVal.Value);

            case ControlType.Button:
                return(currentVal.HasValue && currentVal.Value == 1);

            case ControlType.Pov:
                if (currentVal.HasValue)
                {
                    return(Common.InputSupport.Util.GetPovDirection(currentVal.Value) == hotkey.PovDirection);
                }
                return(false);

            case ControlType.Key:
                return(currentVal.HasValue && currentVal.Value == 1);
            }
            return(false);
        }
Пример #3
0
        public bool CheckIfMatches(PhysicalControlStateChangedEventArgs directInputEvent, InputControlSelection inputControlSelection)
        {
            if (directInputEvent == null)
            {
                return(false);
            }
            if (directInputEvent.Control == null)
            {
                return(false);
            }
            if (inputControlSelection == null)
            {
                return(false);
            }

            if (
                inputControlSelection.ControlType != ControlType.Axis
                &&
                inputControlSelection.ControlType != ControlType.Button
                &&
                inputControlSelection.ControlType != ControlType.Pov
                )
            {
                return(false);
            }
            if (inputControlSelection.DirectInputControl == null)
            {
                return(false);
            }
            if (inputControlSelection.DirectInputDevice == null)
            {
                return(false);
            }

            if (
                directInputEvent.Control.ControlType == inputControlSelection.DirectInputControl.ControlType
                &&
                directInputEvent.Control.ControlNum == inputControlSelection.DirectInputControl.ControlNum
                &&
                (
                    (directInputEvent.Control.ControlType == ControlType.Axis &&
                     directInputEvent.Control.AxisType == inputControlSelection.DirectInputControl.AxisType)
                    ||
                    (directInputEvent.Control.ControlType != ControlType.Axis)
                )
                &&
                Equals(directInputEvent.Control.Parent.Key, inputControlSelection.DirectInputDevice.Key)
                &&
                (
                    directInputEvent.Control.ControlType != ControlType.Pov
                    ||
                    (
                        inputControlSelection.ControlType == ControlType.Pov
                        &&
                        inputControlSelection.PovDirection == Util.GetPovDirection(directInputEvent.CurrentState)
                    )
                )
                &&
                (
                    directInputEvent.Control.ControlType != ControlType.Button
                    ||
                    (
                        directInputEvent.Control.ControlType == ControlType.Button
                        &&
                        directInputEvent.CurrentState == 1
                    )
                )
                )
            {
                return(true);
            }
            return(false);
        }