InputControlType ListenForControl(BindingListenOptions listenOptions, InputDevice device)
        {
            if (device.IsKnown)
            {
                var controlCount = device.Controls.Count;
                for (var i = 0; i < controlCount; i++)
                {
                    var control = device.Controls[i];
                    if (control != null && IsPressed(control))
                    {
                        if (listenOptions.IncludeNonStandardControls || control.IsStandard)
                        {
                            var target = control.Target;
                            if (target == InputControlType.Command && listenOptions.IncludeNonStandardControls)
                            {
                                continue;
                            }
                            return(target);
                        }
                    }
                }
            }

            return(InputControlType.None);
        }
 private Mouse ListenForControl(BindingListenOptions listenOptions)
 {
     if (listenOptions.IncludeMouseButtons)
     {
         for (Mouse mouse = Mouse.None; mouse <= Mouse.Button9; mouse++)
         {
             if (MouseBindingSource.ButtonIsPressed(mouse))
             {
                 return(mouse);
             }
         }
     }
     if (listenOptions.IncludeMouseScrollWheel)
     {
         if (MouseBindingSource.NegativeScrollWheelIsActive(ScrollWheelThreshold))
         {
             return(Mouse.NegativeScrollWheel);
         }
         if (MouseBindingSource.PositiveScrollWheelIsActive(ScrollWheelThreshold))
         {
             return(Mouse.PositiveScrollWheel);
         }
     }
     return(Mouse.None);
 }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (detectFound != Mouse.None)
            {
                if (!IsPressed(detectFound))
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new MouseBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var control = ListenForControl(listenOptions);

            if (control != Mouse.None)
            {
                if (detectPhase == 1)
                {
                    detectFound = control;
                    detectPhase = 2; // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1; // Wait for press.
                }
            }

            return(null);
        }
        Mouse ListenForControl(BindingListenOptions listenOptions)
        {
            if (listenOptions.IncludeMouseButtons)
            {
                for (var control = Mouse.None; control <= Mouse.Button9; control++)
                {
                    if (MouseBindingSource.ButtonIsPressed(control))
                    {
                        return(control);
                    }
                }
            }

            if (listenOptions.IncludeMouseScrollWheel)
            {
                if (MouseBindingSource.NegativeScrollWheelIsActive(ScrollWheelThreshold))
                {
                    return(Mouse.NegativeScrollWheel);
                }

                if (MouseBindingSource.PositiveScrollWheelIsActive(ScrollWheelThreshold))
                {
                    return(Mouse.PositiveScrollWheel);
                }
            }

            return(Mouse.None);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeKeys)
            {
                return(null);
            }
            if (detectFound.IncludeCount > 0 && !detectFound.IsPressed && detectPhase == 2)
            {
                KeyBindingSource result = new KeyBindingSource(detectFound);
                Reset();
                return(result);
            }
            KeyCombo keyCombo = KeyCombo.Detect(listenOptions.IncludeModifiersAsFirstClassKeys);

            if (keyCombo.IncludeCount > 0)
            {
                if (detectPhase == 1)
                {
                    detectFound = keyCombo;
                    detectPhase = 2;
                }
            }
            else if (detectPhase == 0)
            {
                detectPhase = 1;
            }
            return(null);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeUnknownControllers || device.IsKnown)
            {
                return(null);
            }
            if (detectPhase == DetectPhase.WaitForControlRelease && (bool)detectFound && !IsPressed(detectFound, device))
            {
                UnknownDeviceBindingSource result = new UnknownDeviceBindingSource(detectFound);
                Reset();
                return(result);
            }
            UnknownDeviceControl control = ListenForControl(listenOptions, device);

            if ((bool)control)
            {
                if (detectPhase == DetectPhase.WaitForControlPress)
                {
                    detectFound = control;
                    detectPhase = DetectPhase.WaitForControlRelease;
                }
            }
            else if (detectPhase == DetectPhase.WaitForInitialRelease)
            {
                detectPhase = DetectPhase.WaitForControlPress;
            }
            return(null);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeControllers || device.IsUnknown)
            {
                return(null);
            }
            if (detectFound != 0 && !IsPressed(detectFound, device) && detectPhase == 2)
            {
                DeviceBindingSource result = new DeviceBindingSource(detectFound);
                Reset();
                return(result);
            }
            InputControlType inputControlType = ListenForControl(listenOptions, device);

            if (inputControlType != 0)
            {
                if (detectPhase == 1)
                {
                    detectFound = inputControlType;
                    detectPhase = 2;
                }
            }
            else if (detectPhase == 0)
            {
                detectPhase = 1;
            }
            return(null);
        }
Esempio n. 8
0
        public static PlayerActions CreateWithDefaultBindings()
        {
            PlayerActions playerActions = new PlayerActions();

            playerActions.Fire.AddDefaultBinding(Key.A);
            playerActions.Fire.AddDefaultBinding(InputControlType.Action1);
            playerActions.Fire.AddDefaultBinding(Mouse.LeftButton);
            playerActions.Jump.AddDefaultBinding(Key.Space);
            playerActions.Jump.AddDefaultBinding(InputControlType.Action3);
            playerActions.Jump.AddDefaultBinding(InputControlType.Back);
            playerActions.Up.AddDefaultBinding(Key.UpArrow);
            playerActions.Down.AddDefaultBinding(Key.DownArrow);
            playerActions.Left.AddDefaultBinding(Key.LeftArrow);
            playerActions.Right.AddDefaultBinding(Key.RightArrow);
            playerActions.Left.AddDefaultBinding(InputControlType.LeftStickLeft);
            playerActions.Right.AddDefaultBinding(InputControlType.LeftStickRight);
            playerActions.Up.AddDefaultBinding(InputControlType.LeftStickUp);
            playerActions.Down.AddDefaultBinding(InputControlType.LeftStickDown);
            playerActions.Left.AddDefaultBinding(InputControlType.DPadLeft);
            playerActions.Right.AddDefaultBinding(InputControlType.DPadRight);
            playerActions.Up.AddDefaultBinding(InputControlType.DPadUp);
            playerActions.Down.AddDefaultBinding(InputControlType.DPadDown);
            playerActions.Up.AddDefaultBinding(Mouse.PositiveY);
            playerActions.Down.AddDefaultBinding(Mouse.NegativeY);
            playerActions.Left.AddDefaultBinding(Mouse.NegativeX);
            playerActions.Right.AddDefaultBinding(Mouse.PositiveX);
            playerActions.ListenOptions.IncludeUnknownControllers   = true;
            playerActions.ListenOptions.MaxAllowedBindings          = 4u;
            playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
            playerActions.ListenOptions.OnBindingFound = delegate(PlayerAction action, BindingSource binding)
            {
                if (binding == new KeyBindingSource(Key.Escape))
                {
                    action.StopListeningForBinding();
                    return(false);
                }
                return(true);
            };
            BindingListenOptions listenOptions = playerActions.ListenOptions;

            listenOptions.OnBindingAdded = (Action <PlayerAction, BindingSource>) Delegate.Combine(listenOptions.OnBindingAdded, (Action <PlayerAction, BindingSource>) delegate(PlayerAction action, BindingSource binding)
            {
                Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name);
            });
            BindingListenOptions listenOptions2 = playerActions.ListenOptions;

            listenOptions2.OnBindingRejected = (Action <PlayerAction, BindingSource, BindingSourceRejectionType>) Delegate.Combine(listenOptions2.OnBindingRejected, (Action <PlayerAction, BindingSource, BindingSourceRejectionType>) delegate(PlayerAction action, BindingSource binding, BindingSourceRejectionType reason)
            {
                Debug.Log("Binding rejected... " + reason);
            });
            return(playerActions);
        }
 private UnknownDeviceControl ListenForControl(BindingListenOptions listenOptions, InputDevice device)
 {
     if (device.IsUnknown)
     {
         UnknownDeviceControl firstPressedButton = device.GetFirstPressedButton();
         if ((bool)firstPressedButton)
         {
             return(firstPressedButton);
         }
         UnknownDeviceControl firstPressedAnalog = device.GetFirstPressedAnalog();
         if ((bool)firstPressedAnalog)
         {
             return(firstPressedAnalog);
         }
     }
     return(UnknownDeviceControl.None);
 }
Esempio n. 10
0
        UnknownDeviceControl ListenForControl(BindingListenOptions listenOptions, InputDevice device)
        {
            if (device.IsUnknown)
            {
                var button = device.GetFirstPressedButton();
                if (button)
                {
                    return(button);
                }

                var analog = device.GetFirstPressedAnalog();
                if (analog)
                {
                    return(analog);
                }
            }

            return(UnknownDeviceControl.None);
        }
 private InputControlType ListenForControl(BindingListenOptions listenOptions, InputDevice device)
 {
     if (device.IsKnown)
     {
         int count = device.Controls.Count;
         for (int i = 0; i < count; i++)
         {
             InputControl inputControl = device.Controls[i];
             if (inputControl != null && IsPressed(inputControl) && (listenOptions.IncludeNonStandardControls || inputControl.IsStandard))
             {
                 InputControlType target = inputControl.Target;
                 if (target != InputControlType.Command || !listenOptions.IncludeNonStandardControls)
                 {
                     return(target);
                 }
             }
         }
     }
     return(InputControlType.None);
 }
Esempio n. 12
0
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeKeys)
            {
                return(null);
            }

            if (detectFound.Count > 0)
            {
                if (!detectFound.IsPressed)
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new KeyBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var keyCombo = KeyCombo.Detect(listenOptions.IncludeModifiersAsFirstClassKeys);

            if (keyCombo.Count > 0)
            {
                if (detectPhase == 1)
                {
                    detectFound = keyCombo;
                    detectPhase = 2;                     // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1;                     // Wait for press.
                }
            }

            return(null);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeControllers || device.IsUnknown)
            {
                return(null);
            }

            if (detectFound != InputControlType.None)
            {
                if (!IsPressed(detectFound, device))
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new DeviceBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var control = ListenForControl(listenOptions, device);

            if (control != InputControlType.None)
            {
                if (detectPhase == 1)
                {
                    detectFound = control;
                    detectPhase = 2;                     // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1;                     // Wait for press.
                }
            }

            return(null);
        }
Esempio n. 14
0
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeUnknownControllers || device.IsKnown)
            {
                return(null);
            }

            if (detectPhase == DetectPhase.WaitForControlRelease && detectFound)
            {
                if (!IsPressed(detectFound, device))
                {
                    var bindingSource = new UnknownDeviceBindingSource(detectFound);
                    Reset();
                    return(bindingSource);
                }
            }

            var control = ListenForControl(listenOptions, device);

            if (control)
            {
                if (detectPhase == DetectPhase.WaitForControlPress)
                {
                    detectFound = control;
                    detectPhase = DetectPhase.WaitForControlRelease;
                }
            }
            else
            {
                if (detectPhase == DetectPhase.WaitForInitialRelease)
                {
                    detectPhase = DetectPhase.WaitForControlPress;
                }
            }

            return(null);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (detectFound != 0 && !IsPressed(detectFound) && detectPhase == 2)
            {
                MouseBindingSource result = new MouseBindingSource(detectFound);
                Reset();
                return(result);
            }
            Mouse mouse = ListenForControl(listenOptions);

            if (mouse != 0)
            {
                if (detectPhase == 1)
                {
                    detectFound = mouse;
                    detectPhase = 2;
                }
            }
            else if (detectPhase == 0)
            {
                detectPhase = 1;
            }
            return(null);
        }