示例#1
0
文件: MainWindow.cs 项目: kg/DS4_PSO2
 private bool InitJoystick(uint id)
 {
     return(VJoy.TryAcquire(id));
 }
示例#2
0
文件: MainWindow.cs 项目: kg/DS4_PSO2
        private bool UpdateJoystick(uint id, DateTime[] gestureTimes)
        {
            var now = DateTime.UtcNow;

            VJoy.JoystickState state = default(VJoy.JoystickState);

            state.bDevice  = (byte)id;
            state.AxisX    = RescaleSignedAxis(CurrentDualShock.Axes[DualShock4Axis.LeftStickX]);
            state.AxisY    = RescaleSignedAxis(CurrentDualShock.Axes[DualShock4Axis.LeftStickY]);
            state.AxisXRot = RescaleSignedAxis(CurrentDualShock.Axes[DualShock4Axis.RightStickX]);
            state.AxisYRot = RescaleSignedAxis(CurrentDualShock.Axes[DualShock4Axis.RightStickY]);

            // Separate trigger axes
            state.AxisZRot = RescaleUnsignedAxis(CurrentDualShock.Axes[DualShock4Axis.L2]);
            state.Slider   = RescaleUnsignedAxis(CurrentDualShock.Axes[DualShock4Axis.R2]);

            // XBox 360 DInput style triggers (unified axis)
            var z = 0f +
                    (CurrentDualShock.Axes[DualShock4Axis.R2] * -1) +
                    (CurrentDualShock.Axes[DualShock4Axis.L2] * 1);

            state.AxisZ = RescaleSignedAxis(z);

            uint     buttons = 0;
            TimeSpan delta;

            for (var i = 0; i < gestureTimes.Length; i++)
            {
                delta = now - gestureTimes[i];

                // We hold a virtual button for a set number of milliseconds after a gesture
                SetButton(
                    ref buttons, GestureButtonBase + i,
                    (delta.TotalMilliseconds < GesturePressDuration)
                    );
            }

            // Then shortly after the gesture button press we press a confirmation button
            // If you perform the same gesture again, it resets the timer for the confirmation
            //  so that you can swipe multiple times before one confirmation happens
            delta = (now - MostRecentTouchUpTime);

            GestureConfirmActive = (delta.TotalMilliseconds >= GestureConfirmDelay) &&
                                   (delta.TotalMilliseconds <= GestureConfirmDelay + GesturePressDuration);

            // If they held the touch long enough for it to repeat a few times, we confirm
            //  immediately after the hold ends.
            delta = (now - MostRecentHeldTouchUpTime);

            GestureConfirmActive |= (delta.TotalMilliseconds >= GesturePressDuration) &&
                                    (delta.TotalMilliseconds <= (GesturePressDuration * 2));

            if (GestureConfirmActive && GestureConfirmButton.HasValue)
            {
                if (!ShownConfirmMessage)
                {
                    ShownConfirmMessage   = true;
                    MostRecentGestureText = "Confirm (auto)";
                }
            }
            else
            {
                ShownConfirmMessage = false;
            }

            SetButton(ref buttons, 0, DualShock4Button.Cross);
            SetButton(ref buttons, 1, DualShock4Button.Circle);
            SetButton(ref buttons, 2, DualShock4Button.Square);
            SetButton(ref buttons, 3, DualShock4Button.Triangle);

            SetButton(ref buttons, 4, DualShock4Button.L1);
            SetButton(ref buttons, 5, DualShock4Button.R1);
            SetButton(ref buttons, 6, DualShock4Button.Share);
            SetButton(ref buttons, 7, DualShock4Button.Options);
            SetButton(ref buttons, 8, DualShock4Button.L3);
            SetButton(ref buttons, 9, DualShock4Button.R3);

            const float leftAxisThreshold  = 0.55f;
            const float rightAxisThreshold = 0.55f;

            SetButton(ref buttons, 10, (CurrentDualShock.Axes[DualShock4Axis.L2] > leftAxisThreshold));
            SetButton(ref buttons, 11, (CurrentDualShock.Axes[DualShock4Axis.R2] > rightAxisThreshold));

            SetButton(ref buttons, AfterGestureButtonBase, DualShock4Button.PS);
            SetButton(ref buttons, AfterGestureButtonBase + 1, DualShock4Button.TouchpadClick);

            foreach (var kvp in AutoFireButtons)
            {
                var autoFireButtonState = CurrentDualShock.Buttons[kvp.Key];
                var buttonState         = GetButton(buttons, kvp.Value);

                DateTime pressedWhen;
                if (ButtonPressedWhen.TryGetValue(kvp.Key, out pressedWhen))
                {
                    if (autoFireButtonState)
                    {
                        const int modulo = AutoFireDelayMs + AutoFireDurationMs;

                        var pressedDuration        = now - pressedWhen;
                        var pressedDurationRounded = pressedDuration.TotalMilliseconds % modulo;

                        if (pressedDurationRounded >= AutoFireDurationMs)
                        {
                            autoFireButtonState = false;
                        }
                    }
                    else
                    {
                        ButtonPressedWhen.Remove(kvp.Key);
                    }
                }
                else
                {
                    ButtonPressedWhen[kvp.Key] = now;
                }

                SetButton(ref buttons, kvp.Value, autoFireButtonState || buttonState);
            }

            state.Buttons = buttons;
            state.bHats   = DPadMapping[CurrentDualShock.DPad];

            return(VJoy.UpdateVJD(id, ref state));
        }
示例#3
0
文件: MainWindow.cs 项目: kg/DS4_PSO2
 private void DeInitJoystick(uint id)
 {
     VJoy.RelinquishVJD(id);
 }