Ejemplo n.º 1
0
            void DelayedAwake( )
            {
                m_inputs.Add(new KeyboardInput());

                int totalXInputs = 0;

                for (int i = 0; i < 4; ++i)
                {
                    if (XInputController.TestIfConnected(i))
                    {
                        m_inputs.Add(new XInputController(i));
                        ++totalXInputs;
                    }
                }


                string[] unityInput = Input.GetJoystickNames();
                for (int i = 0; i < unityInput.Length; ++i)
                {
                    // Ignore XInput controllers
                    if (unityInput[i].StartsWith("Controller (XBOX") && totalXInputs > 0)
                    {
                        --totalXInputs;
                        continue;
                    }

                    m_inputs.Add(new GenericJoystick(i));
                }


                m_isInited = true;
            }
Ejemplo n.º 2
0
        public override void Execute(XInputController controller)
        {
            List <ModifierKeys> modifiers = new List <ModifierKeys>();
            var elements = Modifier.Split(',');

            foreach (var modifier in elements)
            {
                ModifierKeys result;
                if (Enum.TryParse(modifier, out result))
                {
                    modifiers.Add(result);
                }
            }

            List <Keys> keys      = new List <Keys>();
            var         elements2 = Key.Split(',');

            foreach (var key in elements2)
            {
                Keys result;
                if (Enum.TryParse(key, out result))
                {
                    keys.Add(result);
                }
            }

            this.input.KeyDownWithModifier(modifiers, keys);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Remaps a XInput button mapped to a buton struct to the controller button map struct.
        /// </summary>
        /// <param name="timeoutSeconds">The timeout in seconds for the controller assignment.</param>
        /// <param name="currentTimeout">The current amount of time left in seconds, use this to update the GUI.</param>
        /// <param name="buttonToMap">Specififies the button variable where the index of the pressed button will be written to. Either a member of Controller_Button_Mapping or Emulation_Button_Mapping</param>
        /// <param name="cancellationToken">The method polls on this boolean such that if it is set to true, the method will exit.</param>
        /// <returns>True if a new button has successfully been assigned by the user.</returns>
        private bool XInputRemapButton(int timeoutSeconds, out float currentTimeout, ref byte buttonToMap, ref bool cancellationToken)
        {
            // Cast Controller to DInput Controller
            XInputController xInputController = (XInputController)Controller;

            // Retrieve Joystick State
            bool[] buttonState = xInputController.GetButtons();

            // Initialize Timeout
            int pollAttempts = timeoutSeconds * MillisecondsInSecond / SleepTimePolling;
            int pollCounter  = 0;

            // Poll the controller properties.
            while (pollCounter < pollAttempts)
            {
                // Get new JoystickState
                bool[] buttonStateNew = xInputController.GetButtons();

                // Iterate over all buttons.
                for (int x = 0; x < buttonStateNew.Length; x++)
                {
                    if (buttonState[x] != buttonStateNew[x])
                    {
                        // Retrieve the button mapping.
                        ControllerCommon.ButtonMapping buttonMapping = Controller.InputMappings.ButtonMapping;

                        // Assign requested button.
                        buttonToMap = (byte)x;

                        // Reassign button mapping.
                        Controller.InputMappings.ButtonMapping = buttonMapping;

                        // Set timeout to 0
                        currentTimeout = 0;

                        // Return
                        return(true);
                    }
                }

                // Increase counter, calculate new time left.
                pollCounter   += 1;
                currentTimeout = timeoutSeconds - pollCounter * SleepTimePolling / (float)MillisecondsInSecond;

                // Check exit condition
                if (cancellationToken)
                {
                    return(false);
                }

                // Sleep
                Thread.Sleep(SleepTimePolling);
            }

            // Assign the current timeout.
            currentTimeout = 0;
            return(false);
        }
Ejemplo n.º 4
0
    void InitControllers()
    {
        controllers = new XInputController[maxControllers];

        for (int i = 0; i < maxControllers; i++)
        {
            controllers[i] = new XInputController(i);
        }
    }
Ejemplo n.º 5
0
        /// <summary>
        /// The Remapper class provides the means of loading and saving individual configurations for
        /// each DirectInput and XInput Device in question.
        /// Separate implementations are provided for both DirectInput and XInput.
        /// </summary>
        /// <param name="deviceType">The type of the device (XInput)</param>
        /// <param name="xInputController">The directInput controller instance.</param>
        public Remapper(InputDeviceType deviceType, XInputController xInputController)
        {
            DeviceType = deviceType;
            Controller = xInputController;
            XInputPort = xInputController.ControllerId;

            // Retrieve the configuration location.
            GetConfigLocation(null);
        }
Ejemplo n.º 6
0
 protected void AddXInputDevices(List <IMappableDevice> deviceList, bool connectedOnly)
 {
     foreach (UserIndex userIndex in XINPUT_USER_INDEXES)
     {
         XInputController controller = new XInputController(userIndex);
         if (!connectedOnly || controller.IsConnected())
         {
             deviceList.Add(controller);
         }
     }
 }
Ejemplo n.º 7
0
        public cKeyInput(cKeyInterruptControl KEYCNT, cIF IF)
        {
            this.KEYCNT = KEYCNT;
            this.IF     = IF;

            // attempt to update controller state
            if (!this.xinput.UpdateState())
            {
                // if there is no controller connected, an exception will be thrown and we can instead
                // initialize the register with only the keyboardcontroller
                this.xinput = new NoXInputController();

                // todo: recognize new controller if one is plugged in
            }
        }
Ejemplo n.º 8
0
    public void Update()
    {
        m_CurrentController = InputSystem.GetDevice <XInputController>();

        if (m_CurrentController == null)
        {
            return;
        }

        if (((ButtonControl)m_CurrentController[buttonToTrack.ToString()]).isPressed)
        {
            stateImage.color = m_RedTransparent;
        }
        else
        {
            stateImage.color = m_WhiteTransparent;
        }
    }
Ejemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        m_CurrentController = (XInputController)XInputController.current;

        if (m_CurrentController == null)
        {
            return;
        }

        if (((ButtonControl)m_CurrentController[buttonToTrack.ToString()]).isPressed)
        {
            stateImage.color = m_RedTransparent;
        }
        else
        {
            stateImage.color = m_WhiteTransparent;
        }
    }
Ejemplo n.º 10
0
 public static void LoadControllers()
 {
     Controllers.Clear();
     foreach (var dev in MuniaController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in ArduinoController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in XInputController.ListDevices())
     {
         Controllers.Add(dev);
     }
     foreach (var dev in MappedController.ListDevices())
     {
         Controllers.Add(dev);
     }
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Boolean running = true;

            Console.WriteLine("STARTING PROGRAM");
            Console.Write("CONNECTING CONTROLLER ... ");
            XInputController c = new XInputController();

            Console.WriteLine((c.connected) ? "CONNECTED!" : "CONTROLLER FAILED TO CONNECT!");
            if (c.connected == false)
            {
                Console.WriteLine("ENDING PROGRAM");
                return;
            }
            Console.Write("TRYING TO CONNECT TO ARDUINO ... ");
            UdpClient  udp = new UdpClient(80);
            IPEndPoint ep  = new IPEndPoint(IPAddress.Parse("192.168.4.1"), 80);

            udp.Connect(ep);
            Console.WriteLine("POSSIBLY A SUCCESS.");

            while (running)
            {
                int degree = (int)point_direction(0, 0, (int)c.leftThumb.x, (int)c.leftThumb.y);
                int speed  = getSpeed(c.leftThumb.x, c.leftThumb.y);
                //Console.WriteLine(value);
                if (Math.Floor(c.leftThumb.x) == 0 && Math.Floor(c.leftThumb.y) == 0)
                {
                    sendMessage(udp, "s", 1);
                }
                else
                {
                    sendMessage(udp, "l", degree);
                    sendMessage(udp, "n", speed);
                    //Console.WriteLine(degree + " " + speed);
                }

                c.Update();
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 12
0
        public void ControllerScan()
        {
            while (_active)
            {
                // Check validity of connected controllers
                var deadControllers = new List <IController>();

                foreach (var controller in Controllers)
                {
                    if (controller.IsAlive())
                    {
                        continue;
                    }

                    Log.WriteLine($"XInput device {controller.Name} was disconnected.");
                    controller.Stop();
                    deadControllers.Add(controller);
                }

                // Remove disconnected devices
                if (deadControllers.Count > 0)
                {
                    Controllers.RemoveAll(c => deadControllers.Contains(c));
                }

                // Update controller list
                for (int i = 0; i < 4; i++)
                {
                    var controller = XboxController.RetrieveController(i);
                    if (!controller.IsConnected || Controllers.Any(device => device.UnderlyingController == controller))
                    {
                        continue;
                    }
                    var xdevice = new XInputController(i);
                    Log.WriteLine($"XInput device {xdevice.Name} was connected.");
                    Controllers.Add(xdevice);
                }

                Thread.Sleep(2000);
            }
        }
Ejemplo n.º 13
0
        private static void Inputtest()
        {
            var ctrl = new XInputController(UserIndex.One);

            if (!ctrl.IsConnected)
            {
                //return;
            }

            char keyChar = ' ';

            do
            {
                if (Console.KeyAvailable)
                {
                    keyChar = Console.ReadKey().KeyChar;
                }

                ctrl.Update();
                Console.WriteLine(ctrl);
            } while (keyChar != 'x');
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets up the DirectInput controllers and Initializes the XInput Controllers.
        /// Basically instantiates all of the controllers and sets them up.
        /// </summary>
        public void SetupControllerManager()
        {
            // Clear current controller (on hotplug events)
            Controllers.Clear();

            // Acquire the DirectInput devices. (Finds, loads and sets up all DInput Devices)
            DInputManager.AcquireDevices();

            // Instantiate three XInput Controllers
            XInputController xInputController1 = new XInputController(0);
            XInputController xInputController2 = new XInputController(1);
            XInputController xInputController3 = new XInputController(2);
            XInputController xInputController4 = new XInputController(3);

            // Place all controllers in Controllers list.
            Controllers.AddRange(DInputManager.RetrieveDevices());
            Controllers.Add(xInputController1);
            Controllers.Add(xInputController2);
            Controllers.Add(xInputController3);
            Controllers.Add(xInputController4);

            // Fire hotplug delegate.
            ControllerHotplugEventDelegate?.Invoke();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            var            wpfwindow = new WpfApplication.MainWindow();
            InputSimulator sim       = new InputSimulator();

            ElementHost.EnableModelessKeyboardInterop(wpfwindow);
            wpfwindow.Show();

            while (true)
            {
                XInputController controller = new XInputController();

                controller.Update();

                var CLY = controller.leftThumb.Y;
                var CLX = controller.leftThumb.X;
                var CRY = controller.rightThumb.Y;
                var CRX = controller.rightThumb.X;
                var CRT = controller.rightTrigger;
                var CLT = controller.leftTrigger;

                int LY = Convert.ToInt32(CLY);
                int LX = Convert.ToInt32(CLX);
                int RY = Convert.ToInt32(CRY);
                int RX = Convert.ToInt32(CRX);
                int LT = Convert.ToInt32(CLT);
                int RT = Convert.ToInt32(CRT);

                Wait(1);
                int TimeUnit = 100;

                int YP = (int)Math.Round((double)(100 * LY) / TimeUnit);
                wpfwindow.LYPlus.Value  = YP;
                wpfwindow.LYMinus.Value = YP * -1;

                int XP = (int)Math.Round((double)(100 * LX) / TimeUnit);
                wpfwindow.LXPlus.Value  = XP;
                wpfwindow.LXMinus.Value = XP * -1;

                int RYP = (int)Math.Round((double)(100 * RY) / TimeUnit);
                wpfwindow.RYPlus.Value  = RYP;
                wpfwindow.RYMinus.Value = RYP * -1;

                int RXP = (int)Math.Round((double)(100 * RX) / TimeUnit);
                wpfwindow.RXPlus.Value  = RXP;
                wpfwindow.RXMinus.Value = RXP * -1;

                int RTP = (int)Math.Round((double)(39 * RT) / TimeUnit);
                wpfwindow.RTProg.Value = RTP;

                int LTP = (int)Math.Round((double)(39 * LT) / TimeUnit);
                wpfwindow.LTProg.Value = LTP;

                wpfwindow.DZLP.Value = wpfwindow.DZL.Value;
                wpfwindow.DZRP.Value = wpfwindow.DZR.Value;

                wpfwindow.LBP.Value = wpfwindow.LBPS.Value;
                wpfwindow.RBP.Value = wpfwindow.RBPS.Value;

                wpfwindow.TBP.Value  = wpfwindow.TBS.Value;
                wpfwindow.TDZP.Value = wpfwindow.DZT.Value;

                if (wpfwindow.LUP_Button.IsPressed)
                {
                }

                if (wpfwindow.TrigDisable.IsChecked == false)
                {
                    //Trigger Loop

                    if (RTP > (100 + (-wpfwindow.TBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.RCONTROL);
                    }
                    ;

                    if (LTP > (100 + (-wpfwindow.TBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.RCONTROL);
                    }
                    ;

                    if (RTP > wpfwindow.TDZP.Value)
                    {
                        Debug.WriteLine(RTP);
                        sim.Keyboard.KeyDown(VirtualKeyCode.VK_R);
                        Wait(RTP);
                        sim.Keyboard.KeyUp(VirtualKeyCode.VK_R);
                        Wait(TimeUnit - RTP);
                    }

                    if (LTP > wpfwindow.TDZP.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.VK_L);
                        Wait(LTP);
                        sim.Keyboard.KeyUp(VirtualKeyCode.VK_L);
                        Wait(TimeUnit - LTP);
                    }

                    sim.Keyboard.KeyUp(VirtualKeyCode.RCONTROL);
                }

                if (wpfwindow.LeftDisable.IsChecked == false)
                {
                    // Left Thumbstick Loop

                    if (YP > (100 + (-wpfwindow.LBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                    }
                    ;
                    if (-YP > (100 + (-wpfwindow.LBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                    }
                    ;
                    if (XP > (100 + (-wpfwindow.LBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                    }
                    ;
                    if (-XP > (100 + (-wpfwindow.LBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                    }
                    ;

                    if (YP > wpfwindow.DZL.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.VK_W);
                        Wait(YP);
                        sim.Keyboard.KeyUp(VirtualKeyCode.VK_W);
                        Wait(TimeUnit - YP);
                    }
                    if (YP < -wpfwindow.DZL.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.VK_S);
                        Wait(YP * -1);
                        sim.Keyboard.KeyUp(VirtualKeyCode.VK_S);
                        Wait(TimeUnit - (YP * -1));
                    }

                    if (XP > wpfwindow.DZL.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.VK_D);
                        Wait(XP);
                        sim.Keyboard.KeyUp(VirtualKeyCode.VK_D);
                        Wait(TimeUnit - XP);
                    }
                    if (XP < -wpfwindow.DZL.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.VK_A);
                        Wait(XP * -1);
                        sim.Keyboard.KeyUp(VirtualKeyCode.VK_A);
                        Wait(TimeUnit - XP * -1);
                    }

                    sim.Keyboard.KeyUp(VirtualKeyCode.SHIFT);
                }

                if (wpfwindow.RightDisable.IsChecked == false)
                {
                    // Right Thumbstick Loop

                    if (RYP > (100 + (-wpfwindow.RBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    }
                    ;
                    if (-RYP > (100 + (-wpfwindow.RBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    }
                    ;
                    if (RXP > (100 + (-wpfwindow.RBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    }
                    ;
                    if (-RXP > (100 + (-wpfwindow.RBP.Value)))
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    }
                    ;

                    if (RXP > wpfwindow.DZR.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.UP);
                        Wait(RXP);
                        sim.Keyboard.KeyUp(VirtualKeyCode.UP);
                        Wait(TimeUnit - RXP);
                    }
                    if (RXP < -wpfwindow.DZR.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.DOWN);
                        Wait(RXP * -1);
                        sim.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                        Wait(TimeUnit - (RXP * -1));
                    }

                    if (RYP > wpfwindow.DZR.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.RIGHT);
                        Wait(RYP);
                        sim.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                        Wait(TimeUnit - RYP);
                    }
                    if (RYP < -wpfwindow.DZR.Value)
                    {
                        sim.Keyboard.KeyDown(VirtualKeyCode.LEFT);
                        Wait(RYP * -1);
                        sim.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                        Wait(TimeUnit - RYP * -1);
                    }

                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                }

                if (wpfwindow.IsLoaded == false)
                {
                    break;
                }
            }
            ;
            void Wait(int ms)
            {
                DateTime start = DateTime.Now;

                while ((DateTime.Now - start).TotalMilliseconds < ms)
                {
                    System.Windows.Forms.Application.DoEvents();
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// The param <paramref name="newValue"/> must be between [0-1]. If it's out of bounds, it will be clamped anyway.
 /// </summary>
 public static void SetTriggerMinValueToConsiderPressedOrReleased(float newValue)
 {
     XInputController.SetTriggerMinValueToConsiderPressedOrReleased(newValue);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// The param <paramref name="newRadius"/> must be between [0-1]. If it's out of bounds, it will be clamped anyway.
 /// </summary>
 public static void SetDeadZoneRadius(float newRadius)
 {
     XInputController.SetDeadZoneRadius(newRadius);
 }
Ejemplo n.º 18
0
 public virtual void Execute(XInputController controller)
 {
 }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            InputSimulator sim = new InputSimulator();

            Console.Title           = "PWMove by Elisha Shaddock";
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Clear();
            Console.WriteLine();


            while (true)
            {
                XInputController controller = new XInputController();
                controller.Update();

                var CLY      = controller.leftThumb.Y;
                var CLX      = controller.leftThumb.X;
                int LY       = Convert.ToInt32(CLY);
                int LX       = Convert.ToInt32(CLX);
                int TimeUnit = 100;
                int YP       = (int)Math.Round((double)(100 * LY) / TimeUnit);
                int XP       = (int)Math.Round((double)(100 * LX) / TimeUnit);

                if (YP > 1)
                {
                    sim.Keyboard.KeyDown(VirtualKeyCode.VK_W);
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine(" Y Axis Ontime Percentage:  " + YP);
                    System.Threading.Thread.Sleep(YP);

                    Console.WriteLine(" Y Axis Offtime Percentage: " + (TimeUnit - YP));
                    sim.Keyboard.KeyUp(VirtualKeyCode.VK_W);
                    System.Threading.Thread.Sleep(TimeUnit - YP);
                }
                if (YP < 0)
                {
                    sim.Keyboard.KeyDown(VirtualKeyCode.VK_S);
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("-Y Axis Ontime Percentage:  " + (YP * -1));
                    System.Threading.Thread.Sleep(YP * -1);

                    Console.WriteLine("-Y Axis Offtime Percentage: " + (TimeUnit - (YP * -1)));
                    sim.Keyboard.KeyUp(VirtualKeyCode.VK_S);
                    System.Threading.Thread.Sleep(TimeUnit - (YP * -1));
                }

                if (XP > 0)
                {
                    sim.Keyboard.KeyDown(VirtualKeyCode.VK_D);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(" X Axis Ontime Percentage:  " + XP);
                    System.Threading.Thread.Sleep(XP);

                    Console.WriteLine(" X Axis Offtime Percentage: " + (TimeUnit - XP));
                    sim.Keyboard.KeyUp(VirtualKeyCode.VK_D);
                    System.Threading.Thread.Sleep(TimeUnit - XP);
                }
                if (XP < 0)
                {
                    sim.Keyboard.KeyDown(VirtualKeyCode.VK_A);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("-X Axis Ontime Percentage:  " + XP * -1);
                    System.Threading.Thread.Sleep(XP * -1);

                    Console.WriteLine("-X Axis Offtime Percentage: " + (TimeUnit - (XP * -1)));
                    sim.Keyboard.KeyUp(VirtualKeyCode.VK_A);
                    System.Threading.Thread.Sleep(TimeUnit - XP * -1);
                }
            }
            ;
        }
Ejemplo n.º 20
0
 public override void Execute(XInputController controller)
 {
     this.input.Text(this.Key);
 }
Ejemplo n.º 21
0
 public override void Execute(XInputController controller)
 {
     controller.Vibrate(Amount, Duration);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Remaps the axis of an XInput controller.
        /// </summary>
        private bool XInputRemapAxis(int timeoutSeconds, out float currentTimeout, ControllerCommon.AxisMappingEntry mappingEntry, ref bool cancellationToken)
        {
            // Cast Controller to DInput Controller
            XInputController xInputController = (XInputController)Controller;

            // Retrieve Joystick State
            State joystickState = xInputController.Controller.GetState();

            // Initialize Timeout
            // MillisecondsInSecond / SleepTimePolling = Amount of polls/ticks per second.
            int pollAttempts = timeoutSeconds * MillisecondsInSecond / SleepTimePolling;
            int pollCounter  = 0;

            // Get % Change for recognition of input.
            int percentDelta        = (int)(XInputController.MaxAnalogStickRangeXinput / 100.0F * PercentageAxisDelta);
            int percentDeltaTrigger = (int)(XInputController.MaxTriggerRangeXinput / 100.0F * PercentageAxisDelta);

            // Poll the controller properties.
            while (pollCounter < pollAttempts)
            {
                // Get new JoystickState
                State joystickStateNew = xInputController.Controller.GetState();

                // Get Deltas (Differences)
                int leftStickX   = joystickState.Gamepad.LeftThumbX - joystickStateNew.Gamepad.LeftThumbX;
                int leftStickY   = joystickState.Gamepad.LeftThumbY - joystickStateNew.Gamepad.LeftThumbY;
                int rightStickX  = joystickState.Gamepad.RightThumbX - joystickStateNew.Gamepad.RightThumbX;
                int rightStickY  = joystickState.Gamepad.RightTrigger - joystickStateNew.Gamepad.RightThumbY;
                int leftTrigger  = joystickState.Gamepad.LeftTrigger - joystickStateNew.Gamepad.LeftTrigger;
                int rightTrigger = joystickState.Gamepad.RightTrigger - joystickStateNew.Gamepad.RightTrigger;

                // Iterate over all axis.
                if (leftStickX < -1 * percentDelta)
                {
                    mappingEntry.IsReversed = true; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.LeftStickX; currentTimeout = 0; return(true);
                }
                if (leftStickX > percentDelta)
                {
                    mappingEntry.IsReversed = false; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.LeftStickX; currentTimeout = 0; return(true);
                }

                if (rightStickX < -1 * percentDelta)
                {
                    mappingEntry.IsReversed = true; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.RightStickX; currentTimeout = 0; return(true);
                }
                if (rightStickX > percentDelta)
                {
                    mappingEntry.IsReversed = false; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.RightStickX; currentTimeout = 0; return(true);
                }

                if (leftStickY < -1 * percentDelta)
                {
                    mappingEntry.IsReversed = true; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.LeftStickY; currentTimeout = 0; return(true);
                }
                if (leftStickY > percentDelta)
                {
                    mappingEntry.IsReversed = false; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.LeftStickY; currentTimeout = 0; return(true);
                }

                if (rightStickY < -1 * percentDelta)
                {
                    mappingEntry.IsReversed = true; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.RightStickY; currentTimeout = 0; return(true);
                }
                if (rightStickY > percentDelta)
                {
                    mappingEntry.IsReversed = false; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.RightStickY; currentTimeout = 0; return(true);
                }

                if (leftTrigger < -1 * percentDeltaTrigger)
                {
                    mappingEntry.IsReversed = true; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.LeftTrigger; currentTimeout = 0; return(true);
                }
                if (leftTrigger > percentDeltaTrigger)
                {
                    mappingEntry.IsReversed = false; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.LeftTrigger; currentTimeout = 0; return(true);
                }

                if (rightTrigger < -1 * percentDeltaTrigger)
                {
                    mappingEntry.IsReversed = true; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.RightTrigger; currentTimeout = 0; return(true);
                }
                if (rightTrigger > percentDeltaTrigger)
                {
                    mappingEntry.IsReversed = false; mappingEntry.DestinationAxis = ControllerCommon.ControllerAxis.RightTrigger; currentTimeout = 0; return(true);
                }

                // Increase counter, calculate new time left.
                // SleepTimePolling / MillisecondsInSecond = Amount of time per 1 tick (pollCounter)
                // pollCOunter = current amount of ticks done.
                pollCounter   += 1;
                currentTimeout = (float)timeoutSeconds - (pollCounter * (SleepTimePolling / MillisecondsInSecond));

                // Check exit condition
                if (cancellationToken)
                {
                    return(false);
                }

                // Sleep
                Thread.Sleep(SleepTimePolling);
            }

            // Set current timeout (suppress compiler)
            currentTimeout = 0;
            return(false);
        }