Пример #1
0
        public void OnReceiveData(ref DualShockState state)
        {
            // Macro
            if (UsingMacroPlayer)
            {
                MacroPlayer.OnReceiveData(ref state);
            }
            // Mapping
            else
            {
                if (!CheckFocusedWindow())
                {
                    return;
                }

                // Create the default state to modify
                if (CurrentState == null)
                {
                    CurrentState = new DualShockState()
                    {
                        Battery = 255
                    };
                }

                // Mouse Input
                if (EnableMouseInput)
                {
                    var checkState = new DualShockState();

                    // Left mouse
                    var leftMap = MappingsDataBinding.ElementAtOrDefault(LeftMouseMapping);
                    if (leftMap != null)
                    {
                        if (LeftMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, leftMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, leftMap.Property);
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, defaultValue);
                        }
                    }


                    // Right mouse
                    var rightMap = MappingsDataBinding.ElementAtOrDefault(RightMouseMapping);
                    if (rightMap != null)
                    {
                        if (RightMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, rightMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, rightMap.Property);
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, defaultValue);
                        }
                    }

                    // Middle mouse
                    var middleMap = MappingsDataBinding.ElementAtOrDefault(MiddleMouseMapping);
                    if (middleMap != null)
                    {
                        if (MiddleMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, middleMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, middleMap.Property);
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, defaultValue);
                        }
                    }

                    // Mouse moved
                    if (CurrentMouseStroke != null && CurrentMouseStroke.DidMoved)
                    {
                        MouseSpeedX = (CurrentMouseStroke.VelocityX * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;
                        if (MouseInvertXAxis)
                        {
                            MouseSpeedX *= -1;
                        }

                        MouseSpeedY = (CurrentMouseStroke.VelocityY * MouseSensitivity) / MOUSE_SENSITIVITY_DIVISOR;
                        if (MouseInvertYAxis)
                        {
                            MouseSpeedY *= -1;
                        }

                        CurrentMouseStroke.DidMoved = false;

                        // Stop release timer
                        //if (MouseReleaseTimer != null)
                        //{
                        //    MouseReleaseTimer.Stop();
                        //    MouseReleaseTimer = null;
                        //}
                    }
                    // Mouse idle
                    else
                    {
                        // Start decay
                        MouseSpeedX /= MouseDecayRate;
                        MouseSpeedY /= MouseDecayRate;

                        // Stop decaying joystick if below threshold
                        //if (Math.Abs(MouseSpeedX) < MouseDecayThreshold || Math.Abs(MouseSpeedY) < MouseDecayThreshold)
                        //{
                        //    // Reset mouse speed
                        //    if (Math.Abs(MouseSpeedX) < MouseDecayThreshold) MouseSpeedX = 0;
                        //    if (Math.Abs(MouseSpeedY) < MouseDecayThreshold) MouseSpeedY = 0;

                        //    // Start release timer
                        //    if (MouseReleaseTimer == null)
                        //    {
                        //        MouseReleaseTimer = new System.Timers.Timer(MOUSE_RELEASE_TIME);
                        //        MouseReleaseTimer.Start();
                        //        MouseReleaseTimer.Elapsed += (s, e) =>
                        //        {
                        //            // Recenter cursor
                        //            RemapperUtility.SetCursorPosition(MOUSE_CENTER_X, MOUSE_CENTER_Y);

                        //            // Reset cursor overflow
                        //            CursorOverflowX = 0;
                        //            CursorOverflowY = 0;

                        //            // Stop release timer
                        //            MouseReleaseTimer.Stop();
                        //            MouseReleaseTimer = null;
                        //        };

                        //    }
                        //}
                    }

                    const double min            = 0;
                    const double max            = 255;
                    string       analogProperty = MouseMovementAnalog == AnalogStick.Left ? "L" : "R";

                    // Minimum speed
                    double positiveSpeed = 128 + MouseAnalogDeadzone;
                    double negativeSpeed = 128 - MouseAnalogDeadzone;

                    // Base speed
                    double baseX = ((MouseSpeedX > 0) ? positiveSpeed : ((MouseSpeedX < 0) ? negativeSpeed : 128));
                    double baseY = ((MouseSpeedY > 0) ? positiveSpeed : ((MouseSpeedY < 0) ? negativeSpeed : 128));

                    // Makeup speed
                    double makeupX = Math.Sign(MouseSpeedX) * MouseMakeupSpeed;
                    double makeupY = Math.Sign(MouseSpeedY) * MouseMakeupSpeed;

                    // Scale speed to analog values
                    double rx = baseX + (makeupX * MouseSpeedX * MouseSpeedX * 127);
                    double ry = baseY + (makeupY * MouseSpeedY * MouseSpeedY * 127);

                    byte scaledX = (byte)((rx < min) ? min : (rx > max) ? max : rx);
                    byte scaledY = (byte)((ry < min) ? min : (ry > max) ? max : ry);

                    // Set the analog values
                    RemapperUtility.SetValue(CurrentState, analogProperty + "X", scaledX);
                    RemapperUtility.SetValue(CurrentState, analogProperty + "Y", scaledY);

                    // Invoke callback
                    OnMouseAxisChanged?.Invoke(scaledX, scaledY);
                }

                // Assign the state
                state = CurrentState;
            }
        }
Пример #2
0
        public void OnReceiveData(ref DualShockState state)
        {
            // Macro
            if (UsingMacroPlayer)
            {
                MacroPlayer.OnReceiveData(ref state);
            }
            // Mapping
            else
            {
                if (!CheckFocusedWindow())
                {
                    return;
                }

                // Create the default state to modify
                if (CurrentState == null)
                {
                    CurrentState = new DualShockState()
                    {
                        Battery = 255
                    };
                }

                // Mouse Input
                if (EnableMouseInput)
                {
                    var checkState = new DualShockState();

                    // Left mouse
                    var leftMap = MappingsDataBinding.ElementAtOrDefault(LeftMouseMapping);
                    if (leftMap != null)
                    {
                        if (LeftMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, leftMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, leftMap.Property);
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, defaultValue);
                        }
                    }


                    // Right mouse
                    var rightMap = MappingsDataBinding.ElementAtOrDefault(RightMouseMapping);
                    if (rightMap != null)
                    {
                        if (RightMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, rightMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, rightMap.Property);
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, defaultValue);
                        }
                    }

                    // Middle mouse
                    var middleMap = MappingsDataBinding.ElementAtOrDefault(MiddleMouseMapping);
                    if (middleMap != null)
                    {
                        if (MiddleMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, middleMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, middleMap.Property);
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, defaultValue);
                        }
                    }


                    string analogProperty = MouseMovementAnalog == AnalogStick.Left ? "L" : "R";

                    // Moving mouse

                    // Move mouse to center everytime
                    if (Counter <= 0)
                    {
                        double CenteredX = CurrentX - 127.5;
                        double CenteredY = CurrentY - 127.5;

                        CurrentX = CurrentX - ((CenteredX / 1000) * MouseDecayThreshold);
                        CurrentY = CurrentY - ((CenteredY / 1000) * MouseDecayThreshold);
                    }
                    else
                    {
                        Counter = Math.Max(0, Counter - 1);
                    }

                    // Limit borders
                    if (CurrentX > 255 - MouseAnalogDeadzone)
                    {
                        CurrentX = 255 - MouseAnalogDeadzone;
                    }
                    else if (CurrentX < MouseAnalogDeadzone)
                    {
                        CurrentX = MouseAnalogDeadzone;
                    }

                    if (CurrentY > 255 - MouseAnalogDeadzone)
                    {
                        CurrentY = 255 - MouseAnalogDeadzone;
                    }
                    else if (CurrentY < MouseAnalogDeadzone)
                    {
                        CurrentY = MouseAnalogDeadzone;
                    }

                    // Set values
                    RemapperUtility.SetValue(CurrentState, analogProperty + "X", CurrentX);
                    RemapperUtility.SetValue(CurrentState, analogProperty + "Y", CurrentY);

                    // Invoke callback - set visible icon in settings
                    OnMouseAxisChanged?.Invoke((int)CurrentX, (int)CurrentY);
                }

                // Assign the state
                state = CurrentState;
            }
        }
Пример #3
0
        public void OnReceiveData(ref DualShockState state)
        {
            // Macro
            if (UsingMacroPlayer)
            {
                MacroPlayer.OnReceiveData(ref state);
            }
            // Mapping
            else
            {
                if (!CheckFocusedWindow())
                {
                    return;
                }

                // Create the default state to modify
                if (CurrentState == null)
                {
                    CurrentState = new DualShockState()
                    {
                        Battery = 255
                    };
                }

                // Mouse Input
                if (EnableMouseInput)
                {
                    var checkState = new DualShockState();

                    // Left mouse
                    var leftMap = MappingsDataBinding.ElementAtOrDefault(LeftMouseMapping);
                    if (leftMap != null)
                    {
                        if (LeftMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, leftMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, leftMap.Property);
                            RemapperUtility.SetValue(CurrentState, leftMap.Property, defaultValue);
                        }
                    }


                    // Right mouse
                    var rightMap = MappingsDataBinding.ElementAtOrDefault(RightMouseMapping);
                    if (rightMap != null)
                    {
                        if (RightMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, rightMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, rightMap.Property);
                            RemapperUtility.SetValue(CurrentState, rightMap.Property, defaultValue);
                        }
                    }

                    // Middle mouse
                    var middleMap = MappingsDataBinding.ElementAtOrDefault(MiddleMouseMapping);
                    if (middleMap != null)
                    {
                        if (MiddleMouseDown)
                        {
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, middleMap.Value);
                        }
                        else
                        {
                            var defaultValue = RemapperUtility.GetValue(checkState, middleMap.Property);
                            RemapperUtility.SetValue(CurrentState, middleMap.Property, defaultValue);
                        }
                    }


                    string analogProperty = MouseMovementAnalog == AnalogStick.Left ? "L" : "R";

                    // Moving mouse

                    // Move mouse every X frames
                    if (TempFrame >= FrameRefresh)
                    {
                        TempFrame    = 0;
                        CurrentX     = 127.5 + TempCurrentX;
                        CurrentY     = 127.5 + TempCurrentY;
                        TempCurrentX = 0;
                        TempCurrentY = 0;

                        // Limit borders
                        if (CurrentX > 255 - Borders)
                        {
                            CurrentX = 255 - Borders;
                        }
                        else if (CurrentX < Borders)
                        {
                            CurrentX = Borders;
                        }

                        if (CurrentY > 255 - Borders)
                        {
                            CurrentY = 255 - Borders;
                        }
                        else if (CurrentY < Borders)
                        {
                            CurrentY = Borders;
                        }

                        // Set values
                        RemapperUtility.SetValue(CurrentState, analogProperty + "X", CurrentX);
                        RemapperUtility.SetValue(CurrentState, analogProperty + "Y", CurrentY);

                        // Invoke callback - set visible icon in settings
                        OnMouseAxisChanged?.Invoke((int)CurrentX, (int)CurrentY);
                    }
                    else
                    {
                        TempFrame = TempFrame + 1;
                    }
                }

                // Assign the state
                state = CurrentState;
            }
        }