Ejemplo n.º 1
0
        public ButtonInfo GetInput()
        {
            if (controller == null || !controller.IsConnected)
            {
                return(null);
            }

            var buttonInfo = new ButtonInfo();

            var state = controller.GetState();

            buttonInfo.A = ((state.Gamepad.Buttons & GamepadButtonFlags.A) != 0);
            buttonInfo.B = ((state.Gamepad.Buttons & GamepadButtonFlags.B) != 0);
            buttonInfo.X = ((state.Gamepad.Buttons & GamepadButtonFlags.X) != 0);
            buttonInfo.Y = ((state.Gamepad.Buttons & GamepadButtonFlags.Y) != 0);

            buttonInfo.DPad.Up    = ((state.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0);
            buttonInfo.DPad.Down  = ((state.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0);
            buttonInfo.DPad.Left  = ((state.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0);
            buttonInfo.DPad.Right = ((state.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0);

            buttonInfo.XAxis = state.Gamepad.LeftThumbX;
            buttonInfo.YAxis = state.Gamepad.LeftThumbY;

            buttonInfo.Start = ((state.Gamepad.Buttons & GamepadButtonFlags.Start) != 0);

            SaveState(buttonInfo);

            return(buttonInfo);
        }
Ejemplo n.º 2
0
        // Experimental
        //private void MoveTo(int angle)
        //{
        //    var angleHigh = angle + 20;
        //    var angleLow = angle - 20;

        //    if (angleHigh > 360)
        //    {
        //        if (angleLow < 360)
        //            angle = 0;
        //    }
        //    else if (angleHigh > 270)
        //    {
        //        if (angleLow < 270)
        //            angle = 270;
        //    }
        //    else if (angleHigh > 180)
        //    {
        //        if (angleLow < 180)
        //            angle = 180;
        //    }
        //    else if (angleHigh > 90)
        //    {
        //        if (angleLow < 90)
        //            angle = 90;
        //    }
        //    else if (angleHigh > 0)
        //    {
        //        if (angleLow < 0)
        //            angle = 0;
        //    }

        //    RotateAngle = angle;
        //}

        private void HandleButtonsSettings(ButtonInfo buttons)
        {
            const int numSettings = 3;

            if (buttons.DPad.Up ||
                (buttons.YAxis > 15000 && Math.Abs(buttons.XAxis) < Math.Abs(buttons.YAxis)))
            {
                settingsPosition = (settingsPosition == 1) ? 1 : (settingsPosition - 1);

                UpdateSettings(updatePosition: true);

                Thread.Sleep(110);
            }
            else if (buttons.DPad.Down ||
                     (buttons.YAxis < -15000 && Math.Abs(buttons.XAxis) < Math.Abs(buttons.YAxis)))
            {
                settingsPosition = (settingsPosition == numSettings) ? numSettings : (settingsPosition + 1);

                UpdateSettings(updatePosition: true);
                Thread.Sleep(110);
            }

            if (controller.IsChanged)
            {
                if (buttons.A)
                {
                    if (settingsPosition == 1)
                    {
                        isExitAfterRun = !isExitAfterRun;
                        UpdateSettings();
                    }
                    else if (settingsPosition == 2)
                    {
                        isHelpVisible = !isHelpVisible;
                        UpdateSettings();
                    }
                    else
                    {
                        NextColour();
                    }
                }
                else if (buttons.B ||
                         buttons.Start)
                {
                    ToggleSettingsMenu();

                    Application.Current?.Dispatcher.Invoke((Action) delegate
                    {
                        exitAfterRunButton.Foreground = new SolidColorBrush(Color.FromRgb(0x66, 0x66, 0x66));
                    });
                }
            }

            return;
        }
Ejemplo n.º 3
0
 private void SaveState(ButtonInfo newButtonInfo)
 {
     if (oldButtonInfo == null ||
         !ButtonInfo.IsEqual(oldButtonInfo, newButtonInfo))
     {
         oldButtonInfo = newButtonInfo;
         IsChanged     = true;
     }
     else
     {
         IsChanged = false;
     }
 }
Ejemplo n.º 4
0
        private void PollForInput()
        {
            var buttons = new ButtonInfo();

            while (controller != null &&
                   controller.IsConnected())
            {
                buttons = controller.GetInput();
                HandleButtons(buttons);
                Thread.Sleep(20);
            }

            PollForDevices();
        }
Ejemplo n.º 5
0
        private async void PollForInput_FileDialog()
        {
            var buttons     = new ButtonInfo();
            var prevbuttons = new ButtonInfo();

            while (controller != null &&
                   controller.IsConnected() &&
                   isFileDialogOpen)
            {
                buttons = controller.GetInput();
                await HandleButtonsFileDialog(buttons);

                Thread.Sleep(20);
            }
        }
Ejemplo n.º 6
0
        private async Task HandleButtonsFileDialog(ButtonInfo buttons)
        {
            if (buttons.DPad.Up ||
                (buttons.YAxis > 15000 && Math.Abs(buttons.XAxis) < Math.Abs(buttons.YAxis)))
            {
                System.Windows.Forms.SendKeys.SendWait("{UP}");

                await Task.Delay(110);
            }
            else if (buttons.DPad.Down ||
                     (buttons.YAxis < -15000 && Math.Abs(buttons.XAxis) < Math.Abs(buttons.YAxis)))
            {
                System.Windows.Forms.SendKeys.SendWait("{DOWN}");

                await Task.Delay(110);
            }
            else if (buttons.DPad.Right ||
                     (buttons.XAxis > 15000 && Math.Abs(buttons.XAxis) > Math.Abs(buttons.YAxis)))
            {
                System.Windows.Forms.SendKeys.SendWait("{RIGHT}");

                await Task.Delay(110);
            }
            else if (buttons.DPad.Left ||
                     (buttons.XAxis < -15000 && Math.Abs(buttons.XAxis) > Math.Abs(buttons.YAxis)))
            {
                System.Windows.Forms.SendKeys.SendWait("{LEFT}");

                await Task.Delay(110);
            }

            if (controller.IsChanged)
            {
                if (buttons.A)
                {
                    System.Windows.Forms.SendKeys.SendWait("{ENTER}");
                }
                else if (buttons.B)
                {
                    System.Windows.Forms.SendKeys.SendWait("%{F4}");
                }
            }

            return;
        }
Ejemplo n.º 7
0
        private void HandleButtons(ButtonInfo buttons)
        {
            if (buttons == null || !IsKeyboardFocusWithin)
            {
                return;
            }

            if (isSettingsOpen)
            {
                HandleButtonsSettings(buttons);
                return;
            }
            var x = (double)(buttons.XAxis / 1000);
            var y = (double)(buttons.YAxis / 1000);

            // Experimental
            //if (Math.Abs(x) > 15 || Math.Abs(y) > 15)
            //{
            //    var rotation = Math.Atan2(x, y);
            //    rotation = rotation * (180.0 / Math.PI);

            //    if (rotation < 0)
            //    {
            //        rotation += 360;
            //    }

            //    MoveTo((int)rotation);
            //}

            if (buttons.DPad.Right ||
                (buttons.XAxis > 15000 && Math.Abs(buttons.XAxis) > Math.Abs(buttons.YAxis)))
            {
                RotateAngle = (double)Slot.Right;
            }
            else if (buttons.DPad.Left ||
                     (buttons.XAxis < -15000 && Math.Abs(buttons.XAxis) > Math.Abs(buttons.YAxis)))
            {
                RotateAngle = (double)Slot.Left;
            }
            else if (buttons.DPad.Up ||
                     (buttons.YAxis > 15000 && Math.Abs(buttons.XAxis) < Math.Abs(buttons.YAxis)))
            {
                RotateAngle = (double)Slot.Top;
                System.Windows.Forms.SendKeys.SendWait("{UP}");
            }
            else if (buttons.DPad.Down ||
                     (buttons.YAxis < -15000 && Math.Abs(buttons.XAxis) < Math.Abs(buttons.YAxis)))
            {
                RotateAngle = (double)Slot.Bottom;
                System.Windows.Forms.SendKeys.SendWait("{DOWN}");
            }

            if (controller.IsChanged)
            {
                if (buttons.A)
                {
                    if (Run() == true)
                    {
                        if (isExitAfterRun)
                        {
                            Thread.Sleep(1000); // Delay before exit
                            CloseThreadSafe();
                        }
                    }
                }
                else if (buttons.B)
                {
                    CloseThreadSafe();
                }
                else if (buttons.X)
                {
                    if (Run() == true)
                    {
                        Thread.Sleep(1000); // Delay before exit
                        CloseThreadSafe();
                    }
                }
                else if (buttons.Y)
                {
                    Application.Current?.Dispatcher.Invoke((Action) delegate
                    {
                        SetExeSlot(slot);
                    });
                }
                else if (buttons.Start)
                {
                    ToggleSettingsMenu();

                    UpdateSettings(updatePosition: true);
                }
            }
        }