/// <summary> /// Sets the gamepad states of all controlled Xbox's /// </summary> /// <param name="pad">Gamepad state to set</param> private void SetGamepadStates(XBOX_AUTOMATION_GAMEPAD pad) { foreach (ControllableXboxViewItem controllableXboxViewItem in this.AllDevices) { try { if (controllableXboxViewItem.Quadrant1Selected) { controllableXboxViewItem.XboxViewItem.XboxDevice.XboxConsole.XboxAutomation.SetGamepadState(0, pad); } else if (controllableXboxViewItem.Quadrant2Selected) { controllableXboxViewItem.XboxViewItem.XboxDevice.XboxConsole.XboxAutomation.SetGamepadState(1, pad); } else if (controllableXboxViewItem.Quadrant3Selected) { controllableXboxViewItem.XboxViewItem.XboxDevice.XboxConsole.XboxAutomation.SetGamepadState(2, pad); } else if (controllableXboxViewItem.Quadrant4Selected) { controllableXboxViewItem.XboxViewItem.XboxDevice.XboxConsole.XboxAutomation.SetGamepadState(3, pad); } } catch { // Ignore failure } } }
//[DllImport("XSimWrapperDll.dll", CharSet = CharSet.Ansi)] //public static extern uint XSimInitialize(UInt32 dwComponentFrameRate); public Program() { manager = new XboxManager(); console = manager.OpenConsole(manager.DefaultConsole); automation = console.XboxAutomation; gamepad = new XBOX_AUTOMATION_GAMEPAD(); result = false; enableMU = false; }
/// <summary> /// Send a right trigger /// </summary> public void PressRightTrigger() { lock (this) { this.handlingVirtualPress = true; XBOX_AUTOMATION_GAMEPAD pad = new XBOX_AUTOMATION_GAMEPAD(); pad.RightTrigger = byte.MaxValue; this.SetGamepadStates(pad); } }
/// <summary> /// Sets a controller button as down (only 1 button can be down at a time using the virtual controller) /// </summary> /// <param name="buttons">Button(s) to press</param> public void SetControllerButtonDown(XboxAutomationButtonFlags buttons) { lock (this) { this.handlingVirtualPress = true; XBOX_AUTOMATION_GAMEPAD pad = new XBOX_AUTOMATION_GAMEPAD(); pad.Buttons = buttons; this.SetGamepadStates(pad); } }
/// <summary> /// Release all controller buttons /// </summary> public void ReleaseControllerButton() { lock (this) { if (this.handlingVirtualPress) { this.handlingVirtualPress = false; XBOX_AUTOMATION_GAMEPAD pad = new XBOX_AUTOMATION_GAMEPAD(); this.SetGamepadStates(pad); } } }
public void BeginOrStop() { if (!bound) { if (moduleContext.SelectedDevices.Count == 0) { MessageBox.Show("Select one or more consoles"); return; } automation = new List <IXboxAutomation>(); foreach (IXboxDevice device in moduleContext.SelectedDevices) { automation.Add(device.XboxConsole.XboxAutomation); } //automation = this.xboxDevice1.XboxConsole.XboxAutomation; gamepad = new XBOX_AUTOMATION_GAMEPAD(); foreach (IXboxAutomation auto in automation) { auto.BindController(quadrant, 1); auto.ClearGamepadQueue(quadrant); auto.ConnectController(quadrant); } bound = true; moduleContext.IsModal = true; } else { foreach (IXboxAutomation auto in automation) { auto.UnbindController(quadrant); } automation.Clear(); bound = false; moduleContext.IsModal = false; } }
/// <summary> /// PollController - ask controller for its state every time the timer 'ticks' /// </summary> /// <param name="obj">Sending object source as another control or event</param> /// <param name="args">Applicable event processing args, if any</param> private void PollController(object obj, EventArgs args) { XBOX_AUTOMATION_GAMEPAD pad = new XBOX_AUTOMATION_GAMEPAD(); GamePadState state = GamePad.GetState(PlayerIndex.One); this.IsControllerConnected = state.IsConnected; if (!state.IsConnected) { return; } // convert button presses from GamePadState to XBOX_AUTOMATION_GAMEPAD if (state.Buttons.A == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.A_Button; } if (state.Buttons.B == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.B_Button; } if (state.Buttons.Back == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.BackButton; } if (state.Buttons.BigButton == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.Xbox360_Button; } if (state.Buttons.LeftShoulder == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.LeftShoulderButton; } if (state.Buttons.LeftStick == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.LeftThumbButton; } if (state.Buttons.RightShoulder == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.RightShoulderButton; } if (state.Buttons.RightStick == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.RightThumbButton; } if (state.Buttons.Start == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.StartButton; } if (state.Buttons.X == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.X_Button; } if (state.Buttons.Y == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.Y_Button; } // convert dpad presses from GamePadState to XBOX_AUTOMATION_GAMEPAD if (state.DPad.Down == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadDown; } if (state.DPad.Left == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadLeft; } if (state.DPad.Right == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadRight; } if (state.DPad.Up == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadUp; } // convert movement from GamePadState to XBOX_AUTOMATION_GAMEPAD // convert movement from GamePadState to XBOX_AUTOMATION_GAMEPAD pad.LeftThumbX = (int)((double)state.ThumbSticks.Left.X * short.MaxValue); pad.LeftThumbY = (int)((double)state.ThumbSticks.Left.Y * short.MaxValue); pad.RightThumbX = (int)((double)state.ThumbSticks.Right.X * short.MaxValue); pad.RightThumbY = (int)((double)state.ThumbSticks.Right.Y * short.MaxValue); pad.LeftTrigger = (uint)((double)state.Triggers.Left * byte.MaxValue); pad.RightTrigger = (uint)((double)state.Triggers.Right * byte.MaxValue); if (this.controlledQuadrant != 0) { try { this.xboxDevice.XboxConsole.XboxAutomation.SetGamepadState(this.controlledQuadrant - 1, pad); } catch (Exception ex) { this.moduleContext.Log("Exception calling SetGamepadState: " + ex.Message); } } }
/// <summary> /// Timer expiration for polling PC controller state /// </summary> private void ControllerTimerExpired() { if (this.closed) { // Short circuit the polling timer return; } GamePadState state = GamePad.GetState(PlayerIndex.One); this.IsControllerConnected = state.IsConnected; if (!state.IsConnected) { // Poll less frequently, for controller to become attached this.controllerTimer.Change(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(-1)); return; } lock (this) { if (this.handlingVirtualPress == false) { // convert button presses from GamePadState to XBOX_AUTOMATION_GAMEPAD XBOX_AUTOMATION_GAMEPAD pad = new XBOX_AUTOMATION_GAMEPAD(); if (state.Buttons.A == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.A_Button; } if (state.Buttons.B == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.B_Button; } if (state.Buttons.Back == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.BackButton; } if (state.Buttons.BigButton == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.Xbox360_Button; } if (state.Buttons.LeftShoulder == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.LeftShoulderButton; } if (state.Buttons.LeftStick == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.LeftThumbButton; } if (state.Buttons.RightShoulder == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.RightShoulderButton; } if (state.Buttons.RightStick == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.RightThumbButton; } if (state.Buttons.Start == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.StartButton; } if (state.Buttons.X == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.X_Button; } if (state.Buttons.Y == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.Y_Button; } // convert dpad presses from GamePadState to XBOX_AUTOMATION_GAMEPAD if (state.DPad.Down == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadDown; } if (state.DPad.Left == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadLeft; } if (state.DPad.Right == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadRight; } if (state.DPad.Up == ButtonState.Pressed) { pad.Buttons = XboxAutomationButtonFlags.DPadUp; } // convert movement from GamePadState to XBOX_AUTOMATION_GAMEPAD pad.LeftThumbX = (int)((double)state.ThumbSticks.Left.X * short.MaxValue); pad.LeftThumbY = (int)((double)state.ThumbSticks.Left.Y * short.MaxValue); pad.RightThumbX = (int)((double)state.ThumbSticks.Right.X * short.MaxValue); pad.RightThumbY = (int)((double)state.ThumbSticks.Right.Y * short.MaxValue); pad.LeftTrigger = (uint)((double)state.Triggers.Left * byte.MaxValue); pad.RightTrigger = (uint)((double)state.Triggers.Right * byte.MaxValue); this.SetGamepadStates(pad); } } this.controllerTimer.Change(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(-1)); }