Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            this.xInputService = new XInputService();
            this.vjoy          = new vJoy();
        }
Esempio n. 2
0
        public GamepadService(IXInputService xinputService)
        {
            var gamepads = this._Gamepads = new[]
            {
                new GamepadViewModel {
                    Name = "Controller 1"
                },
                new GamepadViewModel {
                    Name = "Controller 2"
                },
                new GamepadViewModel {
                    Name = "Controller 3"
                },
                new GamepadViewModel {
                    Name = "Controller 4"
                }
            };

            this.ConnectedSubscription = xinputService.Connected.Subscribe(controllerConnected =>
            {
                var gamepad = gamepads[(int)controllerConnected.UserIndex];
                gamepad.Post(() => gamepad.IsConnected = controllerConnected.Connected);
            });

            this.KeystateSubscription = xinputService.Keystrokes.Subscribe(keystroke =>
            {
                var gamepad = gamepads[(int)keystroke.UserIndex];

                switch (keystroke.VirtualKey)
                {
                case GamepadKeyCode.A: gamepad.Post(() => gamepad.IsAPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.B: gamepad.Post(() => gamepad.IsBPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.X: gamepad.Post(() => gamepad.IsXPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.Y: gamepad.Post(() => gamepad.IsYPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.LeftTrigger: gamepad.Post(() => gamepad.IsLeftTriggerPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.RightTrigger: gamepad.Post(() => gamepad.IsRightTriggerPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.LeftShoulder: gamepad.Post(() => gamepad.IsLeftShoulderPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.RightShoulder: gamepad.Post(() => gamepad.IsRightShoulderPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.Start: gamepad.Post(() => gamepad.IsStartPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.Back: gamepad.Post(() => gamepad.IsBackPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.DPadLeft: gamepad.Post(() => gamepad.IsDPadLeftPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.DPadUp: gamepad.Post(() => gamepad.IsDPadUpPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.DPadRight: gamepad.Post(() => gamepad.IsDPadRightPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;

                case GamepadKeyCode.DPadDown: gamepad.Post(() => gamepad.IsDPadDownPressed = (keystroke.Flags == KeyStrokeFlags.KeyDown)); break;
                }
            });
        }
Esempio n. 3
0
        public MainViewModel(IXInputService xinputService,
                             ISendKeysService sendKeysService,
                             IGamepadService gamepadService,
                             IKeyboardEmulatorService keyboardEmulatorService)
        {
            this.XInputService           = xinputService;
            this.SendKeysService         = sendKeysService;
            this.GamepadService          = gamepadService;
            this.KeyboardEmulatorService = keyboardEmulatorService;

            this.PropertyChanged += this_PropertyChanged;

            this.IsListening = true;
        }
Esempio n. 4
0
 public KeyboardEmulatorService(ISendKeysService sendKeysService,
                                IXInputService xinputService,
                                IInputFactory inputFactory,
                                IMappingService mappingService)
 {
     this.KeystrokeSubscription = xinputService.Keystrokes.Subscribe(keystroke =>
     {
         if (this.IsEnabled)
         {
             if (keystroke.Flags == KeyStrokeFlags.KeyDown)
             {
                 var key = mappingService.Map(keystroke.VirtualKey);
                 if (key != null)
                 {
                     var inputs = inputFactory.GetKeyDownUp(key.Value);
                     sendKeysService.SendKeys(inputs);
                 }
             }
         }
     });
 }