public static void MouseButtonsInput(X360Controller controller)
        {
            MouseState state = mouse.GetCurrentState();

            TRIGGER_LEFT_PRESSED  = state.IsPressed(0);
            TRIGGER_RIGHT_PRESSED = state.IsPressed(1);

            if (state.IsPressed(0))
            {
                controller.RightTrigger = 255;
            }
            else
            {
                if (!TranslateKeyboard.TRIGGER_RIGHT_PRESSED)
                {
                    controller.RightTrigger = 0;
                }
            }

            if (state.IsPressed(1))
            {
                controller.LeftTrigger = 255;
            }
            else
            {
                if (!TranslateKeyboard.TRIGGER_LEFT_PRESSED)
                {
                    controller.LeftTrigger = 0;
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("|-------------------------------|");
            Console.WriteLine("| Switch XBOX Controller Server |");
            Console.WriteLine("|-------------------------------|");
            Console.WriteLine();

            System.Timers.Timer timer;

            _handler += new EventHandler(onExitHandler);
            SetConsoleCtrlHandler(_handler, true);

            detectSwitch();

            Console.WriteLine("Running...");

            controller = new X360Controller();
            scpBus     = new ScpBus();
            scpBus.PlugIn(1);

            timer           = new System.Timers.Timer(1);
            timer.Elapsed  += (s, e) => scpBus.Report(1, controller.GetReport());
            timer.AutoReset = true;
            timer.Start();

            networkThread = new Thread(() => networking());
            displayThread = new Thread(() => displayButtons());

            networkThread.Start();
            displayThread.Start();

            Console.ReadLine();
        }
예제 #3
0
        public void SendtoController(X360Controller controller)
        {
            byte[] report = controller.GetReport();
            byte[] output = new byte[8];

            scpbus.Report(CONTROLLER_NUMBER, report);
        }
예제 #4
0
        private void SetThumbStickAxis(XboxThumbAxis axis, Side side)
        {
            int factor = 200;
            var x      = axis.X * factor;
            var y      = axis.Y * factor;

            if (x > short.MaxValue)
            {
                x = short.MaxValue - 1;
            }
            if (x < short.MinValue)
            {
                x = short.MinValue + 1;
            }
            if (y > short.MaxValue)
            {
                y = short.MaxValue - 1;
            }
            if (y < short.MinValue)
            {
                y = short.MinValue + 1;
            }

            Report.SetAxis(side == Side.LEFT ? Xbox360Axes.LeftThumbX : Xbox360Axes.RightThumbX, (short)(x * -1));
            Report.SetAxis(side == Side.LEFT ? Xbox360Axes.LeftThumbY : Xbox360Axes.RightThumbY, (short)y);
            X360Controller.SendReport(Report);
        }
예제 #5
0
        public void ButtonUp(int Index, X360Buttons Button)
        {
            if (!IsRunning)
            {
                return;
            }

            var current = controllers[Index];
            var next    = new X360Controller(current);

            next.Buttons &= ~Button;

            if (DidEmulateGuide && Button == X360Buttons.RightBumper || Button == X360Buttons.Start)
            {
                next.Buttons   &= ~(X360Buttons.Logo | X360Buttons.RightBumper | X360Buttons.Start);
                DidEmulateGuide = false;
            }

            if (current.Buttons == next.Buttons)
            {
                return;
            }

            controllers[Index] = next;
            InvokeChange(Index);
            if (Program.IsDebug)
            {
                System.Console.WriteLine($"Controller #{Index + 1} {Button} Button Up");
            }
        }
예제 #6
0
        public void ButtonDown(int Index, X360Buttons Button)
        {
            if (!IsRunning)
            {
                return;
            }

            var current = controllers[Index];
            var next    = new X360Controller(current);

            next.Buttons |= Button;

            // RB + Start = Guide
            if (next.Buttons.HasFlag(X360Buttons.RightBumper | X360Buttons.Start))
            {
                next.Buttons   &= ~(X360Buttons.RightBumper | X360Buttons.Start);
                next.Buttons   |= X360Buttons.Logo;
                DidEmulateGuide = true;
            }

            if (current.Buttons == next.Buttons)
            {
                return;
            }

            controllers[Index] = next;
            InvokeChange(Index);
            if (Program.IsDebug)
            {
                System.Console.WriteLine($"Controller #{Index + 1} {Button} Button Down");
            }
        }
예제 #7
0
 /// <summary>
 /// Set X360Controller buttons state from specified strings list
 /// </summary>
 /// <param name="x"></param>
 /// <param name="m"></param>
 public static void SetFromString(this X360Controller x, List <string> m)
 {
     if (m.Count >= 19)
     {
         x.LeftStickX  = CalculateStick(m[0]);
         x.LeftStickY  = CalculateStick(m[1]);
         x.RightStickX = CalculateStick(m[2]);
         x.RightStickY = CalculateStick(m[3]);
         //Buttons
         SetBtn(x, X360Buttons.X, m[4]);
         SetBtn(x, X360Buttons.Y, m[5]);
         SetBtn(x, X360Buttons.A, m[6]);
         SetBtn(x, X360Buttons.B, m[7]);
         //Arrows
         SetBtn(x, X360Buttons.Up, m[8]);
         SetBtn(x, X360Buttons.Down, m[9]);
         SetBtn(x, X360Buttons.Left, m[10]);
         SetBtn(x, X360Buttons.Right, m[11]);
         //Bumpers
         SetBtn(x, X360Buttons.LeftBumper, m[14]);
         SetBtn(x, X360Buttons.RightBumper, m[15]);
         //System
         SetBtn(x, X360Buttons.Back, m[16]);
         SetBtn(x, X360Buttons.Start, m[17]);
         SetBtn(x, X360Buttons.Logo, m[18]);
     }
 }
예제 #8
0
        public static void SendtoController(X360Controller controller)
        {
            byte[] report = controller.GetReport();
            byte[] output = new byte[8];

            // Send our data back to the virtual scp bus.
            scpbus.Report(CONTROLLER_NUMBER, report, output);
        }
예제 #9
0
 /// <summary>
 /// Generates a new X360Controller object with the same values as the specified X360Controller object.
 /// </summary>
 /// <param name="controller">An X360Controller object to copy values from.</param>
 public X360Controller(X360Controller controller)
 {
     Buttons      = controller.Buttons;
     LeftTrigger  = controller.LeftTrigger;
     RightTrigger = controller.RightTrigger;
     LeftStickX   = controller.LeftStickX;
     LeftStickY   = controller.LeftStickY;
     RightStickX  = controller.RightStickX;
     RightStickY  = controller.RightStickY;
 }
예제 #10
0
        public static void SetButton(this X360Controller controller, X360Buttons buttons, bool value)
        {
            var v = controller.Buttons & ~buttons;

            if (value)
            {
                v |= buttons;
            }
            controller.Buttons = v;
        }
예제 #11
0
        //Xbox stream app keeps disconnecting
        //I think having this keepalive function sending
        //a useless but real message with prevent the random
        //disconnection happening
        private void keepalive()
        {
            X360Controller p2 = new X360Controller();

            while (true)
            {
                controller.RightStickY ^= 1;
                scpbus.Report(1, controller.GetReport());
                Thread.Sleep(50);
            }
        }
예제 #12
0
        public static void SetGamepad(bool state)
        {
            scp.Unplug(gamepadIndex);
            scp     = new ScpBus();
            gamepad = new X360Controller();

            if (state)
            {
                scp.PlugIn(gamepadIndex);
            }
        }
예제 #13
0
        private void unplugAll_Click(object sender, EventArgs e)
        {
            bool result = _scpBus.UnplugAll();

            status.Text = result.ToString();

            if (result)
            {
                _controller = new X360Controller();
                ResetControls();
            }
        }
예제 #14
0
        private static void SetBtn(X360Controller x, X360Buttons btn, string state)
        {
            int s = int.Parse(state);

            if (s == 1)
            {
                x.Buttons |= btn;
            }
            else
            {
                x.Buttons &= ~btn;
            }
        }
예제 #15
0
        public override async Task XboxRightTrigger(IAsyncStreamReader <XboxTrigger> triggerStream, IServerStreamWriter <Response> responseStream, ServerCallContext context)
        {
            while (await triggerStream.MoveNext())
            {
                var trigger = triggerStream.Current;

                Report.SetAxis(Xbox360Axes.RightTrigger, (short)trigger.Pressure);
                X360Controller.SendReport(Report);

                Response reply = new Response {
                    Received = true
                };
                await responseStream.WriteAsync(reply);
            }
        }
예제 #16
0
        private static X360Controller CreateController()
        {
            X360Controller controller = new X360Controller();

            try {
                scpbus = new ScpBus();
            } catch (Exception ex) {
                MessageBox.Show("SCP Bus failed to initialize");
                MessageBox.Show(ex.ToString());
            }

            scpbus.PlugIn(1);

            return(controller);
        }
예제 #17
0
        public override async Task DepressXboxButton(IAsyncStreamReader <XboxButton> buttonStream, IServerStreamWriter <Response> responseStream, ServerCallContext context)
        {
            while (await buttonStream.MoveNext())
            {
                var button = buttonStream.Current;

                Report.SetButtonState((Xbox360Buttons)button.Id, false);
                X360Controller.SendReport(Report);

                Response reply = new Response {
                    Received = true
                };
                await responseStream.WriteAsync(reply);
            }
        }
예제 #18
0
        private bool ResetControllerInputs(int controllerNumber)
        {
            X360Controller temp = new X360Controller(_controller);

            _controller = new X360Controller();

            bool result = _scpBus.Report(controllerNumber, _controller.GetReport(), _outputReport);

            CheckRumble();

            if (!result)
            {
                _controller = temp;
            }

            return(result);
        }
예제 #19
0
        private static X360Controller CreateController()
        {
            X360Controller controller = new X360Controller();

            try {
                scpbus = new ScpBus();
            } catch (Exception ex) {
                MessageBox.Show("You probably need to run the ScpToolkit Driver Installer." +
                                System.Environment.NewLine + System.Environment.NewLine + ex.ToString(),
                                "SCP Bus failed to initialize");
                Environment.Exit(-1);
            }

            scpbus.PlugIn(1);

            return(controller);
        }
        private static void Debug_TimeTracer(X360Controller Controller)
        {
            // Get the start time
            var watch = System.Diagnostics.Stopwatch.StartNew();

            // Call the key input
            KeyInput(Controller);

            // Get the end time
            watch.Stop();
            string time = watch.ElapsedMilliseconds + " MS";

            if (time != "0 MS")
            {
                // Display the time
                Logger.appendLogLine("KeyboardInput", $"Timed @ {time}", Logger.Type.Debug);
            }
        }
예제 #21
0
        public override async Task PressXboxButton(IAsyncStreamReader <XboxButton> buttonStream, IServerStreamWriter <Response> responseStream, ServerCallContext context)
        {
            while (await buttonStream.MoveNext())
            {
                var button = buttonStream.Current;
                if (button.Id == 0x9001 && !X360Controller.IsConneced) // Init
                {
                    X360Controller.Connect();
                }

                Report.SetButtonState((Xbox360Buttons)button.Id, true);
                X360Controller.SendReport(Report);

                Response reply = new Response {
                    Received = true
                };
                await responseStream.WriteAsync(reply);
            }
        }
예제 #22
0
        public void StartHooking()
        {
            KeyboardWatcher.Start();
            MouseWatcher.Start();

            MouseWatcher.OnMouseInput  += MouseWatcher_OnMouseInput;
            KeyboardWatcher.OnKeyInput += KeyboardWatcher_OnKeyInput;
            controller = new X360Controller();

            _outputReport = new byte[8];
            try
            {
                _scpBus = new ScpBus();

                _scpBus.PlugIn((int)1);
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #23
0
        public static void MouseButtonsInput(X360Controller controller)
        {
            MouseState state = mouse.GetCurrentState();

            if (state.IsPressed(0))
            {
                controller.RightTrigger = 255;
            }
            else
            {
                controller.RightTrigger = 0;
            }

            if (state.IsPressed(1))
            {
                controller.LeftTrigger = 255;
            }
            else
            {
                controller.LeftTrigger = 0;
            }
        }
예제 #24
0
        private void input_thread(HidDevice Device, ScpBus scpBus, int index)
        {
            scpBus.PlugIn(index);
            X360Controller controller = new X360Controller();
            int            timeout    = 10;
            //long last_changed = 0;
            //long last_mi_button = 0;
            bool ss_button_pressed = false;
            bool ss_button_held    = false;

            while (Running)
            {
                HidDeviceData data         = Device.Read(timeout);
                var           currentState = data.Data;
                //bool changed = false;
                if (data.Status == HidDeviceData.ReadStatus.Success && currentState.Length >= 10 && currentState[0] == 3)
                {
                    // NOTE: Console.WriteLine is blocking. If main thread sends a WriteLine while we do a WriteLine here, we're boned and will miss reports!
                    //Console.WriteLine(Program.ByteArrayToHexString(currentState));

                    X360Buttons Buttons = X360Buttons.None;
                    if ((currentState[3] & 64) != 0)
                    {
                        Buttons |= X360Buttons.A;
                    }
                    if ((currentState[3] & 32) != 0)
                    {
                        Buttons |= X360Buttons.B;
                    }
                    if ((currentState[3] & 16) != 0)
                    {
                        Buttons |= X360Buttons.X;
                    }
                    if ((currentState[3] & 8) != 0)
                    {
                        Buttons |= X360Buttons.Y;
                    }
                    if ((currentState[3] & 4) != 0)
                    {
                        Buttons |= X360Buttons.LeftBumper;
                    }
                    if ((currentState[3] & 2) != 0)
                    {
                        Buttons |= X360Buttons.RightBumper;
                    }
                    if ((currentState[3] & 1) != 0)
                    {
                        Buttons |= X360Buttons.LeftStick;
                    }
                    if ((currentState[2] & 128) != 0)
                    {
                        Buttons |= X360Buttons.RightStick;
                    }
                    ss_button_pressed = (currentState[2] & 1) != 0;
                    // [2] & 2 == Assistant, [2] & 1 == Screenshot

                    switch (currentState[1])
                    {
                    default:
                        break;

                    case 0:
                        Buttons |= X360Buttons.Up;
                        break;

                    case 1:
                        Buttons |= X360Buttons.UpRight;
                        break;

                    case 2:
                        Buttons |= X360Buttons.Right;
                        break;

                    case 3:
                        Buttons |= X360Buttons.DownRight;
                        break;

                    case 4:
                        Buttons |= X360Buttons.Down;
                        break;

                    case 5:
                        Buttons |= X360Buttons.DownLeft;
                        break;

                    case 6:
                        Buttons |= X360Buttons.Left;
                        break;

                    case 7:
                        Buttons |= X360Buttons.UpLeft;
                        break;
                    }

                    if ((currentState[2] & 32) != 0)
                    {
                        Buttons |= X360Buttons.Start;
                    }
                    if ((currentState[2] & 64) != 0)
                    {
                        Buttons |= X360Buttons.Back;
                    }

                    if ((currentState[2] & 16) != 0)
                    {
                        //last_mi_button = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                        Buttons |= X360Buttons.Logo;
                    }


                    //if (controller.Buttons != Buttons)
                    {
                        //changed = true;
                        controller.Buttons = Buttons;
                    }

                    // Note: The HID reports do not allow stick values of 00.
                    // This seems to make sense: 0x80 is center, so usable values are:
                    // 0x01 to 0x7F and 0x81 to 0xFF.
                    // For our purposes I believe this is undesirable. Subtract 1 from negative
                    // values to allow maxing out the stick values.
                    // TODO: Get an Xbox controller and verify this is standard behavior.
                    for (int i = 4; i <= 7; ++i)
                    {
                        if (currentState[i] <= 0x7F && currentState[i] > 0x00)
                        {
                            currentState[i] -= 0x01;
                        }
                    }

                    ushort LeftStickXunsigned = (ushort)(currentState[4] << 8 | (currentState[4] << 1 & 255));
                    if (LeftStickXunsigned == 0xFFFE)
                    {
                        LeftStickXunsigned = 0xFFFF;
                    }
                    short LeftStickX = (short)(LeftStickXunsigned - 0x8000);

                    //if (LeftStickX != controller.LeftStickX)
                    {
                        //	changed = true;
                        controller.LeftStickX = LeftStickX;
                    }

                    ushort LeftStickYunsigned = (ushort)(currentState[5] << 8 | (currentState[5] << 1 & 255));
                    if (LeftStickYunsigned == 0xFFFE)
                    {
                        LeftStickYunsigned = 0xFFFF;
                    }
                    short LeftStickY = (short)(-LeftStickYunsigned + 0x7FFF);
                    if (LeftStickY == -1)
                    {
                        LeftStickY = 0;
                    }
                    //if (LeftStickY != controller.LeftStickY)
                    {
                        //	changed = true;
                        controller.LeftStickY = LeftStickY;
                    }

                    ushort RightStickXunsigned = (ushort)(currentState[6] << 8 | (currentState[6] << 1 & 255));
                    if (RightStickXunsigned == 0xFFFE)
                    {
                        RightStickXunsigned = 0xFFFF;
                    }
                    short RightStickX = (short)(RightStickXunsigned - 0x8000);

                    //if (RightStickX != controller.RightStickX)
                    {
                        //	changed = true;
                        controller.RightStickX = RightStickX;
                    }

                    ushort RightStickYunsigned = (ushort)(currentState[7] << 8 | (currentState[7] << 1 & 255));
                    if (RightStickYunsigned == 0xFFFE)
                    {
                        RightStickYunsigned = 0xFFFF;
                    }
                    short RightStickY = (short)(-RightStickYunsigned + 0x7FFF);
                    if (RightStickY == -1)
                    {
                        RightStickY = 0;
                    }

                    //if (RightStickY != controller.RightStickY)
                    {
                        //	changed = true;
                        controller.RightStickY = RightStickY;
                    }

                    //if (controller.LeftTrigger != currentState[8])
                    {
                        //	changed = true;
                        controller.LeftTrigger = currentState[8];
                    }

                    //if (controller.RightTrigger != currentState[9])
                    {
                        //	changed = true;
                        controller.RightTrigger = currentState[9];
                    }
                }

                /*
                 * if (data.Status == HidDeviceData.ReadStatus.WaitTimedOut || (!changed && ((last_changed + timeout) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))))
                 * {
                 *      changed = true;
                 * }*/

                //if (changed)
                {
                    //Console.WriteLine("changed");
                    //Console.WriteLine((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
                    byte[] outputReport = new byte[8];
                    scpBus.Report(index, controller.GetReport(), outputReport);

                    if (outputReport[1] == 0x08)
                    {
                        byte bigMotor   = outputReport[3];
                        byte smallMotor = outputReport[4];

                        if (smallMotor != Vibration[3] || Vibration[1] != bigMotor)
                        {
                            // We only need to take the mutex if we're modifying the data
                            rumble_mutex.WaitOne();
                            Vibration[1] = bigMotor;
                            Vibration[3] = smallMotor;
                            rumble_mutex.ReleaseMutex();
                            rumbleWaitHandle.Set();
                        }
                    }

                    //last_changed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }

                if (ss_button_pressed && !ss_button_held)
                {
                    ss_button_held = true;
                    try
                    {
                        // TODO: Allow configuring this keybind.
                        ssThread = new Thread(() => System.Windows.Forms.SendKeys.SendWait("^+Z"));
                        ssThread.Start();
                    }
                    catch
                    {
                    }
                }
                else if (ss_button_held && !ss_button_pressed)
                {
                    ss_button_held = false;
                }
            }
        }
예제 #25
0
        private void input_thread(HidDevice Device, ScpBus scpBus, int index)
        {
            scpBus.PlugIn(index);
            X360Controller controller     = new X360Controller();
            int            timeout        = 30;
            long           last_changed   = 0;
            long           last_mi_button = 0;

            while (true)
            {
                HidDeviceData data         = Device.Read(timeout);
                var           currentState = data.Data;
                bool          changed      = false;
                if (data.Status == HidDeviceData.ReadStatus.Success && currentState.Length >= 21 && currentState[0] == 4)
                {
                    //Console.WriteLine(Program.ByteArrayToHexString(currentState));
                    X360Buttons Buttons = X360Buttons.None;
                    if ((currentState[1] & 1) != 0)
                    {
                        Buttons |= X360Buttons.A;
                    }
                    if ((currentState[1] & 2) != 0)
                    {
                        Buttons |= X360Buttons.B;
                    }
                    if ((currentState[1] & 8) != 0)
                    {
                        Buttons |= X360Buttons.X;
                    }
                    if ((currentState[1] & 16) != 0)
                    {
                        Buttons |= X360Buttons.Y;
                    }
                    if ((currentState[1] & 64) != 0)
                    {
                        Buttons |= X360Buttons.LeftBumper;
                    }
                    if ((currentState[1] & 128) != 0)
                    {
                        Buttons |= X360Buttons.RightBumper;
                    }

                    if ((currentState[2] & 32) != 0)
                    {
                        Buttons |= X360Buttons.LeftStick;
                    }
                    if ((currentState[2] & 64) != 0)
                    {
                        Buttons |= X360Buttons.RightStick;
                    }

                    if (currentState[4] != 15)
                    {
                        if (currentState[4] == 0 || currentState[4] == 1 || currentState[4] == 7)
                        {
                            Buttons |= X360Buttons.Up;
                        }
                        if (currentState[4] == 4 || currentState[4] == 3 || currentState[4] == 5)
                        {
                            Buttons |= X360Buttons.Down;
                        }
                        if (currentState[4] == 6 || currentState[4] == 5 || currentState[4] == 7)
                        {
                            Buttons |= X360Buttons.Left;
                        }
                        if (currentState[4] == 2 || currentState[4] == 1 || currentState[4] == 3)
                        {
                            Buttons |= X360Buttons.Right;
                        }
                    }

                    if ((currentState[2] & 8) != 0)
                    {
                        Buttons |= X360Buttons.Start;
                    }
                    if ((currentState[2] & 4) != 0)
                    {
                        Buttons |= X360Buttons.Back;
                    }



                    if ((currentState[20] & 1) != 0)
                    {
                        last_mi_button = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                        Buttons       |= X360Buttons.Logo;
                    }
                    if (last_mi_button != 0)
                    {
                        Buttons |= X360Buttons.Logo;
                    }


                    if (controller.Buttons != Buttons)
                    {
                        changed            = true;
                        controller.Buttons = Buttons;
                    }

                    short LeftStickX = (short)((Math.Max(-127.0, currentState[5] - 128) / 127) * 32767);
                    if (LeftStickX != controller.LeftStickX)
                    {
                        changed = true;
                        controller.LeftStickX = LeftStickX;
                    }

                    short LeftStickY = (short)((Math.Max(-127.0, currentState[6] - 128) / 127) * -32767);
                    if (LeftStickY != controller.LeftStickY)
                    {
                        changed = true;
                        controller.LeftStickY = LeftStickY;
                    }

                    short RightStickX = (short)((Math.Max(-127.0, currentState[7] - 128) / 127) * 32767);
                    if (RightStickX != controller.RightStickX)
                    {
                        changed = true;
                        controller.RightStickX = RightStickX;
                    }

                    short RightStickY = (short)((Math.Max(-127.0, currentState[8] - 128) / 127) * -32767);
                    if (RightStickY != controller.RightStickY)
                    {
                        changed = true;
                        controller.RightStickY = RightStickY;
                    }

                    if (controller.LeftTrigger != currentState[11])
                    {
                        changed = true;
                        controller.LeftTrigger = currentState[11];
                    }

                    if (controller.RightTrigger != currentState[12])
                    {
                        changed = true;
                        controller.RightTrigger = currentState[12];
                    }
                }

                if (data.Status == HidDeviceData.ReadStatus.WaitTimedOut || (!changed && ((last_changed + timeout) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))))
                {
                    changed = true;
                }

                if (changed)
                {
                    //Console.WriteLine("changed");
                    //Console.WriteLine((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
                    byte[] outputReport = new byte[8];
                    scpBus.Report(index, controller.GetReport(), outputReport);

                    if (outputReport[1] == 0x08)
                    {
                        byte bigMotor   = outputReport[3];
                        byte smallMotor = outputReport[4];
                        rumble_mutex.WaitOne();
                        if (bigMotor != Vibration[2] || Vibration[1] != smallMotor)
                        {
                            Vibration[1] = smallMotor;
                            Vibration[2] = bigMotor;
                        }
                        rumble_mutex.ReleaseMutex();
                    }

                    if (last_mi_button != 0)
                    {
                        if ((last_mi_button + 100) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))
                        {
                            last_mi_button      = 0;
                            controller.Buttons ^= X360Buttons.Logo;
                        }
                    }

                    last_changed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }
            }
        }
        private static void KeyInput(X360Controller controller)
        {
            List <bool> btnStatus = new List <bool>();

            //bool tLeft  = false;
            //bool tRight = false;

            try {
                btnStatus.Clear();

                bool mouseDisabled = Program.ActiveConfig.Mouse_Eng_Type == 4;


                // -------------------------------------------------------------------------------
                //                           LEFT STICK, AXIS - X
                // -------------------------------------------------------------------------------
                btnStatus.Clear();
                foreach (KeyValuePair <Key, short> entry in mapLeftStickX)
                {
                    if (entry.Key == Key.None)
                    {
                        continue;
                    }

                    bool v;
                    if (entry.Key == Key.Escape)
                    {
                        v = Hooks.LowLevelKeyboardHook.EscapePressed;
                    }
                    else
                    {
                        v = Keyboard.IsKeyDown(entry.Key);
                    }

                    if (v)
                    {
                        controller.LeftStickX = entry.Value;
                    }
                    btnStatus.Add(v);
                }
                if (!btnStatus.Contains(true) && (mouseDisabled || Program.ActiveConfig.Mouse_Is_RightStick))
                {
                    controller.LeftStickX = 0;
                }


                // -------------------------------------------------------------------------------
                //                           LEFT STICK, AXIS - Y
                // -------------------------------------------------------------------------------
                foreach (KeyValuePair <Key, short> entry in mapLeftStickY)
                {
                    bool v;
                    if (entry.Key == Key.Escape)
                    {
                        v = Hooks.LowLevelKeyboardHook.EscapePressed;
                    }
                    else
                    {
                        v = Keyboard.IsKeyDown(entry.Key);
                    }

                    if (v)
                    {
                        controller.LeftStickY = entry.Value;
                    }

                    btnStatus.Add(v);
                }
                if (!btnStatus.Contains(true) && (mouseDisabled || Program.ActiveConfig.Mouse_Is_RightStick))
                {
                    controller.LeftStickY = 0;
                }


                // -------------------------------------------------------------------------------
                //                           RIGHT STICK, AXIS - X
                // -------------------------------------------------------------------------------
                foreach (KeyValuePair <Key, short> entry in mapRightStickX)
                {
                    bool v;
                    if (entry.Key == Key.Escape)
                    {
                        v = Hooks.LowLevelKeyboardHook.EscapePressed;
                    }
                    else
                    {
                        v = Keyboard.IsKeyDown(entry.Key);
                    }

                    if (v)
                    {
                        controller.RightStickX = entry.Value;
                    }

                    btnStatus.Add(v);
                }
                if (!btnStatus.Contains(true) && (mouseDisabled || !Program.ActiveConfig.Mouse_Is_RightStick))
                {
                    controller.RightStickX = 0;
                }


                // -------------------------------------------------------------------------------
                //                           RIGHT STICK, AXIS - Y
                // -------------------------------------------------------------------------------
                foreach (KeyValuePair <Key, short> entry in mapRightStickY)
                {
                    bool v;
                    if (entry.Key == Key.Escape)
                    {
                        v = Hooks.LowLevelKeyboardHook.EscapePressed;
                    }
                    else
                    {
                        v = Keyboard.IsKeyDown(entry.Key);
                    }

                    if (v)
                    {
                        controller.RightStickY = entry.Value;
                    }

                    btnStatus.Add(v);
                }
                if (!btnStatus.Contains(true) && (mouseDisabled || !Program.ActiveConfig.Mouse_Is_RightStick))
                {
                    controller.RightStickY = 0;
                }


                // -------------------------------------------------------------------------------
                //                                MISC BUTTONS
                // -------------------------------------------------------------------------------
                foreach (KeyValuePair <Key, X360Buttons> entry in buttons)
                {
                    if (entry.Key == Key.None)
                    {
                        continue;
                    }

                    bool v;
                    if (entry.Key == Key.Escape)
                    {
                        v = Hooks.LowLevelKeyboardHook.EscapePressed;
                    }
                    else
                    {
                        v = Keyboard.IsKeyDown(entry.Key);
                    }

                    if (v)
                    {
                        controller.Buttons = controller.Buttons | entry.Value;
                    }
                    else
                    {
                        controller.Buttons = controller.Buttons & ~entry.Value;
                    }
                }


                // -------------------------------------------------------------------------------
                //                                TRIGGERS
                // -------------------------------------------------------------------------------

                foreach (KeyValuePair <Key, TriggerType> entry in triggers)
                {
                    if (entry.Key == Key.None)
                    {
                        continue;
                    }

                    bool v;
                    if (entry.Key == Key.Escape)
                    {
                        v = Hooks.LowLevelKeyboardHook.EscapePressed;
                    }
                    else
                    {
                        v = Keyboard.IsKeyDown(entry.Key);
                    }

                    bool ir = entry.Value == TriggerType.RightTrigger;

                    if (v)
                    {
                        if (ir)
                        {
                            controller.RightTrigger = 255;
                        }
                        else
                        {
                            controller.LeftTrigger = 255;
                        }
                    }
                    else
                    {
                        if (!TranslateKeyboard.TRIGGER_RIGHT_PRESSED && ir)
                        {
                            controller.RightTrigger = 0;
                        }
                        else if (!TranslateKeyboard.TRIGGER_LEFT_PRESSED && ir)
                        {
                            controller.LeftTrigger = 0;
                        }
                    }
                }

                //if (!tLeft)       controller.LeftTrigger = 0;
                //else if (!tRight) controller.RightTrigger = 0;
            } catch (Exception ex) { /* This occures when changing presets */ }
        }
 public static void KeyboardInput(X360Controller controller) =>
     #if (DEBUG)
 // Only enable if you have timing issues AKA Latency on
 // the keyboard inputs
 Debug_TimeTracer(controller);
예제 #28
0
        public virtual X360Controller ToX360()
        {
            X360Controller controller = new X360Controller();

            if (Up)
            {
                controller.Buttons |= X360Buttons.Up;
            }
            if (Down)
            {
                controller.Buttons |= X360Buttons.Down;
            }
            if (Left)
            {
                controller.Buttons |= X360Buttons.Left;
            }
            if (Right)
            {
                controller.Buttons |= X360Buttons.Right;
            }

            if (A || Cross)
            {
                controller.Buttons |= X360Buttons.A;
            }
            if (B || Circle)
            {
                controller.Buttons |= X360Buttons.B;
            }
            if (X || Square)
            {
                controller.Buttons |= X360Buttons.X;
            }
            if (Y || Triangle)
            {
                controller.Buttons |= X360Buttons.Y;
            }

            if (Start)
            {
                controller.Buttons |= X360Buttons.Start;
            }
            if (Select)
            {
                controller.Buttons |= X360Buttons.Back;
            }

            if (Lup)
            {
                controller.LeftStickY = short.MaxValue;
            }
            if (Ldown)
            {
                controller.LeftStickY = short.MinValue;
            }
            if (Lleft)
            {
                controller.LeftStickX = short.MinValue;
            }
            if (Lright)
            {
                controller.LeftStickX = short.MaxValue;
            }
            if (L3)
            {
                controller.Buttons |= X360Buttons.LeftStick;
            }
            if (Rup)
            {
                controller.RightStickY = short.MaxValue;
            }
            if (Rdown)
            {
                controller.RightStickY = short.MinValue;
            }
            if (Rleft)
            {
                controller.RightStickX = short.MinValue;
            }
            if (Rright)
            {
                controller.RightStickX = short.MaxValue;
            }
            if (R3)
            {
                controller.Buttons |= X360Buttons.RightStick;
            }

            if (L1)
            {
                controller.Buttons |= X360Buttons.LeftBumper;
            }
            if (L2)
            {
                controller.LeftTrigger = byte.MaxValue;
            }
            if (R1)
            {
                controller.Buttons |= X360Buttons.RightBumper;
            }
            if (R2)
            {
                controller.RightTrigger = byte.MaxValue;
            }

            return(controller);
        }
예제 #29
0
        private static void Init()
        {
            Controller = CreateController();

            TranslateMouse.InitMouse();
        }
예제 #30
0
 private void PrintButtons(X360Controller input)
 => ConsoleLogger.Info($"Buttons: {input.Buttons} | Lstick: ({input.LeftStickX}, {input.LeftStickY}) | Rstick: ({input.RightStickX}, {input.RightStickY}) | Ltrigger: {input.LeftTrigger} | Rtrigger: {input.RightTrigger}");