public GamePad(OnConnectionChange function) { onConnectionChange += function; controller = new Controller(UserIndex.One); status = Connected; onConnectionChange.Invoke(status); }
public XInputControllerAnalogNode() : base(XInputControllerAnalogNodeFactory.TYPESTRING) { // Prepare Execution Connection conExecuted = new ExecutionConnectorViewModel(); conExecute = new ExecutionConnectorViewModel(); this.InputExecutionConnectors.Add(conExecuted); this.OutputExecutionConnectors.Add(conExecute); // Prepare Connections conLeftThumbX = new ConnectorViewModel("LeftThumbX", typeof(NodeDataNumeric)); conLeftThumbY = new ConnectorViewModel("LeftThumbY", typeof(NodeDataNumeric)); conLeftTrigger = new ConnectorViewModel("LeftTrigger", typeof(NodeDataNumeric)); conRightThumbX = new ConnectorViewModel("RightThumbX", typeof(NodeDataNumeric)); conRightThumbY = new ConnectorViewModel("RightThumbY", typeof(NodeDataNumeric)); conRightTrigger = new ConnectorViewModel("RightTrigger", typeof(NodeDataNumeric)); //conButtons = new ConnectorViewModel("Buttons", typeof(NodeDataXInputButtons)); this.OutputConnectors.Add(conLeftThumbX); this.OutputConnectors.Add(conLeftThumbY); this.OutputConnectors.Add(conLeftTrigger); this.OutputConnectors.Add(conRightThumbX); this.OutputConnectors.Add(conRightThumbY); this.OutputConnectors.Add(conRightTrigger); //this.OutputConnectors.Add(conButtons); // State Values currentUser = UserIndex.One; controller = new SharpDX.XInput.Controller(currentUser); // Create Dialog dlgEdit = new PropertyDialog(); }
public XboxController(Controller controller) { if (controller == null) throw new ArgumentNullException(nameof(controller)); this.controller = controller; }
void MainForm_Load(object sender, EventArgs e) { for (int i = 0; i < 4; i++) { GamePads[i] = new Controller((UserIndex)i); } UpdateTimer = new System.Timers.Timer(); UpdateTimer.AutoReset = false; UpdateTimer.SynchronizingObject = this; UpdateTimer.Interval = 50; UpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(UpdateTimer_Elapsed); SettingsTimer = new System.Timers.Timer(); SettingsTimer.AutoReset = false; SettingsTimer.SynchronizingObject = this; SettingsTimer.Interval = 500; SettingsTimer.Elapsed += new System.Timers.ElapsedEventHandler(SettingsTimer_Elapsed); CleanStatusTimer = new System.Timers.Timer(); CleanStatusTimer.AutoReset = false; CleanStatusTimer.SynchronizingObject = this; CleanStatusTimer.Interval = 3000; CleanStatusTimer.Elapsed += new System.Timers.ElapsedEventHandler(CleanStatusTimer_Elapsed); Text = Helper.GetProductFullName(); // Start Timers. UpdateTimer.Start(); }
public XboxControllerInputProvider(IEventAggregator iEventAggregator) { this.iEventAggregator = iEventAggregator; controllers = new[] { new Controller(UserIndex.One), new Controller(UserIndex.Two), new Controller(UserIndex.Three), new Controller(UserIndex.Four) }; controller = null; FindController(1000); }
public XBox360JoystickProvider(DroneClient droneClient) { if (droneClient == null) throw new ArgumentNullException("DroneClient"); _DroneClient = droneClient; _Controller = new Controller(0); }
public SharpDXGamePad(GamePadNumber number = GamePadNumber.Any) : base(number) { controller = new Controller(GetUserIndexFromNumber()); states = new State[GamePadButton.A.GetCount()]; for (int i = 0; i < states.Length; i++) states[i] = State.Released; }
public XBox360JoystickProvider(DroneClient droneClient) { if (droneClient == null) throw new ArgumentNullException("DroneClient"); _DroneClient = droneClient; _Controller = new Controller(0); _Timer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(timerElapsedHandler), TimeSpan.FromMilliseconds(1000 / 12)); }
private void UpdateInputStates() { KeyboardState = _keyboardManager.GetState(); MouseState = _mouseManager.GetState(); var controller = new Controller(UserIndex.One); if (controller.IsConnected) GamepadState = controller.GetState().Gamepad; }
// ---------------------------------------------------------------------- // XBox // ---------------------------------------------------------------------- private void FindXBoxController() { m_xbox = new SharpDX.XInput.Controller(UserIndex.Any); if (!m_xbox.IsConnected) { Debug.WriteLine("Could not connect to XBox"); } }
public XInputGamePadFactory() { controllers = new Controller[XInputGamePadCount]; for (int i = 0; i < controllers.Length; i++) { controllers[i] = new Controller((UserIndex)i); } }
/// <summary> /// Constructor. /// </summary> /// <param name="gamePadIndex"></param> /// <param name="deadZone"></param> public GamePad(GamePadIndex gamePadIndex, GamePadDeadZone deadZone) { this.Index = gamePadIndex; this.deadZone = deadZone; this.controller = new XInput.Controller(ConvertGamePadIndexToUserIndex(this.Index)); this.state = new XInput.Gamepad(); }
/// <summary> /// Initializes a new instance of the <see cref="XInputCapabilties"/> class. /// </summary> /// <param name="controller">The controller to enumerate.</param> /// <param name="buttonCount">The button count.</param> public XInputCapabilties(XI.Controller controller, int buttonCount) { if (!controller.IsConnected) { return; } GetCaps(buttonCount); }
private Controller(int index) { xboxController = new SharpDX.XInput.Controller((UserIndex)index); CheckConnection(); timer = new Timer(5); timer.Elapsed += (sender, e) => CheckConnection(); timer.Start(); }
/// <summary> /// ctor and init /// </summary> /// <param name="device">A DXInput device</param> /// <param name="hwnd">The WinHandle of the main window</param> /// <param name="panel">The respective JS panel to show the properties</param> public GamepadCls( SharpDX.XInput.Controller device, UC_GpadPanel panel, int tabIndex ) { log.DebugFormat( "GamepadCls ctor - Entry with index {0}", device.ToString( ) ); m_device = device; m_gPanel = panel; MyTabPageIndex = tabIndex; Activated = false; m_senseLimit = AppConfiguration.AppConfig.gpSenseLimit; // can be changed in the app.config file if it is still too little // Set BufferSize in order to use buffered data. log.Debug( "Get GP Objects" ); try { m_gpCaps = m_device.GetCapabilities( DeviceQueryType.Gamepad ); } catch ( Exception ex ) { log.Error( "Get GamepadCapabilities failed", ex ); } m_gPanel.Caption = DevName; int n = 0; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadDown ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadLeft ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadRight ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadUp ) ) n++; m_gPanel.nDPads = n.ToString( ); m_gPanel.DPadE = ( n > 0 ); n = 0; if ( ( m_gpCaps.Gamepad.LeftThumbX != 0 ) || ( m_gpCaps.Gamepad.LeftThumbY != 0 ) || Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.LeftThumb ) ) { n++; m_gPanel.TStickLE = true; } if ( ( m_gpCaps.Gamepad.RightThumbX != 0 ) || ( m_gpCaps.Gamepad.RightThumbY != 0 ) || Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.RightThumb ) ) { n++; m_gPanel.TStickRE = true; } m_gPanel.nTSticks = n.ToString( ); n = 0; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.A ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.B ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.X ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Y ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Start ) ) { n++; m_gPanel.StartE = true; } if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Back ) ) { n++; m_gPanel.BackE = true; } if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.LeftShoulder ) ) { n++; m_gPanel.ShoulderLE = true; } if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.RightShoulder ) ) { n++; m_gPanel.ShoulderRE = true; } m_gPanel.nButtons = n.ToString( ); n = 0; if ( m_gpCaps.Gamepad.LeftTrigger > 0 ) { n++; m_gPanel.TriggerLE = true; } if ( m_gpCaps.Gamepad.RightTrigger > 0 ) { n++; m_gPanel.TriggerRE = true; } m_gPanel.nTriggers = n.ToString( ); m_gPanel.ButtonE = true; // what else ... ApplySettings( ); // get whatever is needed here from Settings Activated = true; }
public override void StartController(Action <int[]> callback) { controller = new SharpDX.XInput.Controller(UserIndex.One); for (int i = 0; i < channels; i++) { controlState[i] = 0; } x = new Thread(() => ControlLoop(callback)); x.Start(); }
private uint[] ServoMappings; // maps a servo to a stick #endregion Fields #region Constructors public Joystick( ServoController[] myServos, double Fs // sampling frequency of the timer ) { this.myServos = myServos; controllerValues = new double[6]; ServoMappings = new uint[myServos.Length]; myController = new Controller(UserIndex.One); oldPacketNumber = 0; myTimer = new Timer(1000.0 / Fs); myTimer.Elapsed += new System.Timers.ElapsedEventHandler(updatePosition); }
// Constructor public Device() { for (int idx = 0; idx < (int)UserIndex.Four; idx++) { Controller cTmp = new Controller((UserIndex)idx); if (cTmp.IsConnected) { // We can add the controller to the devices list now. _Devices.Add(cTmp); } } }
public IInputDevice[] FindDevices() { List<IInputDevice> devices = new List<IInputDevice>(); for (int i = (int)UserIndex.One; i <= (int)UserIndex.Four; i++) { Controller controller = new Controller((UserIndex)i); if (controller.IsConnected) devices.Add(new XboxController(controller)); } return devices.ToArray(); }
static void Main(string[] args) { // box setup Form f = new Form(); f.Opacity = 0.3; f.StartPosition = FormStartPosition.CenterScreen; f.FormBorderStyle = FormBorderStyle.None; f.TopMost = true; bool boxVisible = false; bool wasPressedGuide = false; while (!System.Console.KeyAvailable) { SharpDX.XInput.Controller c = new SharpDX.XInput.Controller(SharpDX.XInput.UserIndex.One); SharpDX.XInput.State s; if (c.GetState(out s)) { //System.Console.WriteLine(s.Gamepad.ToString()); //System.Console.WriteLine(s.Gamepad.Buttons); s.Gamepad.Buttons.HasFlag(SharpDX.XInput.GamepadButtonFlags.A); if (!wasPressedGuide) { if (is_guide_button_down(0) != 0) { wasPressedGuide = true; boxVisible = !boxVisible; //SendKeys.SendWait("{RIGHT}"); } if (boxVisible) { if (!f.Visible) { f.Show(); } } else { f.Hide(); } } else { wasPressedGuide = (is_guide_button_down(0) != 0); } } } }
/// <summary> /// Initializes a new instance of the <see cref="GenericXInputHandler"/> class. /// </summary> public GenericXInputHandler() { m_controllers = new XI.Controller[4]; m_controllers[0] = new XI.Controller(XI.UserIndex.One); m_controllers[1] = new XI.Controller(XI.UserIndex.Two); m_controllers[2] = new XI.Controller(XI.UserIndex.Three); m_controllers[3] = new XI.Controller(XI.UserIndex.Four); m_states = new GamepadState[m_controllers.Length]; for (int loop = 0; loop < m_controllers.Length; loop++) { m_states[loop] = new GamepadState(loop); } }
private void mainLoop() { State gameState; var Controller = new Controller(UserIndex.One); while (running) { Controller.GetState(out gameState); string strState = gameState.Gamepad.Buttons.ToString().Replace(" ", ""); if (strState != "None") { ButtonPressed(getActions(strState), strState.Split(',')); } System.Threading.Thread.Sleep(100); } }
public void Initialize() { Console.Out.WriteLine("Attempting to Connect Controllers"); try { _controller[0] = new Controller(UserIndex.One); // Get Controller at index 0 _controller[1] = new Controller(UserIndex.Two); // Get Controller at index 1 _controller[2] = new Controller(UserIndex.Three); // Get Controller at index 2 _controller[3] = new Controller(UserIndex.Four); // Get Controller at index 3 } catch(Exception ex) { Console.Out.WriteLine(ex); } t = new System.Threading.Timer(TimerCallback, null, 0, 100); // Timer set for 100ms }
private void buttonDisconnect_Click(object sender, RoutedEventArgs e) { if (m_deviceX == null) { return; } m_deviceX.StopPolling(); m_deviceX.Disconnect(); m_deviceX = null; if (m_xbox != null) { m_xbox = null; } StageInitialized = false; }
internal Gamepad() { try { Gamepad1 = new XInput.Controller(XInput.UserIndex.One); Gamepad2 = new XInput.Controller(XInput.UserIndex.Two); Gamepad3 = new XInput.Controller(XInput.UserIndex.Three); Gamepad4 = new XInput.Controller(XInput.UserIndex.Four); IsSupported = true; } catch (Exception ex) { IsSupported = false; Debugging.Log(LogEntryType.Warning, "Unable to find XInput library or it's not supported by your OS - " + ex.HResult.ToHexademicalStringWithPrefix()); Debugging.LogException(LogEntryType.Warning, ex); } //GamepadAny = new XInput.Controller(XInput.UserIndex.Any); GamepadInstance = this; }
private IEnumerable <ILowLevelInputDevice> GetXInputGamepads() { var inputDevices = new List <ILowLevelInputDevice>(); for (int i = 0; i < 4; i++) { var xinput = new SharpDX.XInput.Controller((UserIndex)i); var device = new LowLevelInputDevice() { DiscoveryApi = InputApi.XInput, DI_DeviceType = DeviceType.Gamepad, XI_GamepadIndex = i, XI_IsXInput = true, XI_IsConnected = xinput.IsConnected, }; inputDevices.Add(device); } return(inputDevices); }
static void Main(string[] args) { Controller xbox = new Controller(UserIndex.One); Console.WriteLine("Controller connected: " + xbox.IsConnected); BatteryInformation battery = xbox.GetBatteryInformation(BatteryDeviceType.Gamepad); Console.WriteLine("Battery level: " + battery.BatteryLevel); bool isRunning = true; while (isRunning) { Console.Clear(); State state = xbox.GetState(); switch (state.Gamepad.Buttons) { case GamepadButtonFlags.Start: isRunning = false; break; default: break; } Console.Write("Key pressed: " + state.Gamepad.Buttons + "\n"); Console.Write("RightThumbX stick: " + state.Gamepad.RightThumbX + "\n"); Console.Write("RightThumbY stick: " + state.Gamepad.RightThumbY + "\n"); Console.Write("LeftThumbX stick: " + state.Gamepad.LeftThumbX + "\n"); Console.Write("LeftThumbY stick: " + state.Gamepad.LeftThumbY + "\n"); Console.Write("LeftTrigger: " + state.Gamepad.LeftTrigger + "\n"); Console.Write("RightTrigger: " + state.Gamepad.RightTrigger + "\n"); int vibrationLeftMotorSpeed = 0; if (state.Gamepad.LeftThumbX > -1) vibrationLeftMotorSpeed = state.Gamepad.LeftThumbX; vibration.LeftMotorSpeed = (ushort)vibrationLeftMotorSpeed; xbox.SetVibration(vibration); System.Threading.Thread.Sleep(100); } }
/// <summary> /// The main entry point for the application. /// </summary> public XInputController() { Console.WriteLine("Start XGamepadApp"); // Initialize XInput var controllers = new[] { new SharpDX.XInput.Controller(UserIndex.One), new SharpDX.XInput.Controller(UserIndex.Two), new SharpDX.XInput.Controller(UserIndex.Three), new SharpDX.XInput.Controller(UserIndex.Four) }; // Get 1st controller available SharpDX.XInput.Controller controller = null; foreach (var selectControler in controllers) { if (selectControler.IsConnected) { controller = selectControler; break; } } if (controller == null) { Console.WriteLine("No XInput controller installed"); } else { Console.WriteLine("Found a XInput controller available"); Console.WriteLine("Press buttons on the controller to display events"); // Poll events from joystick var previousState = controller.GetState(); while (controller.IsConnected) { var state = controller.GetState(); if (previousState.PacketNumber != state.PacketNumber) { Console.WriteLine(state.Gamepad); } previousState = state; Thread.Sleep(8);//8 miliseconds = 125Hz } } Console.WriteLine("End XGamepadApp"); }
void MainForm_Load(object sender, EventArgs e) { if (IsDesignMode) return; SettingManager.Settings.Load(); SettingManager.Summaries.Load(); SettingManager.Summaries.Items.ListChanged += Summaries_ListChanged; // Make sure that data will be filtered before loading. // Note: Make sure to load Programs before Games. SettingManager.Programs.FilterList = Programs_FilterList; SettingManager.Programs.Load(); // Make sure that data will be filtered before loading. SettingManager.Games.FilterList = Games_FilterList; SettingManager.Games.Load(); SettingManager.Presets.Load(); SettingManager.PadSettings.Load(); for (int i = 0; i < 4; i++) { GamePads[i] = new Controller((UserIndex)i); } GameToCustomizeComboBox.DataSource = SettingManager.Games.Items; GameToCustomizeComboBox.DisplayMember = "DisplayName"; UpdateTimer = new System.Timers.Timer(); UpdateTimer.AutoReset = false; UpdateTimer.SynchronizingObject = this; UpdateTimer.Interval = DefaultPoolingInterval; UpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(UpdateTimer_Elapsed); SettingsTimer = new System.Timers.Timer(); SettingsTimer.AutoReset = false; SettingsTimer.SynchronizingObject = this; SettingsTimer.Interval = 500; SettingsTimer.Elapsed += new System.Timers.ElapsedEventHandler(SettingsTimer_Elapsed); CleanStatusTimer = new System.Timers.Timer(); CleanStatusTimer.AutoReset = false; CleanStatusTimer.SynchronizingObject = this; CleanStatusTimer.Interval = 3000; CleanStatusTimer.Elapsed += new System.Timers.ElapsedEventHandler(CleanStatusTimer_Elapsed); Text = EngineHelper.GetProductFullName(); SetMinimizeToTray(Settings.Default.MinimizeToTray); // Start Timers. UpdateTimer.Start(); }
public void StartPollingAndSendingCommands(Controller[] controllers) { var commandsQueue = new BlockingCollection<string>(); if (controllers[0].IsConnected) { if (logging) logger.Trace("Found a XInput controller available. Starting PollAndSendMovementCommands"); Thread t = new Thread(() => PollAndSendMovementCommands(controllers[0], commandsQueue)); t.IsBackground = true; t.Start(); } if (controllers[1].IsConnected) { if (logging) logger.Trace("Found a XInput controller available. Starting PollAndSendCameraCommands"); Thread t = new Thread(() => PollAndSendCameraCommands(controllers[1], commandsQueue, cameraStates)); Thread commandsSender = new Thread(() => ProcessCommandQueue(commandsQueue, cameraStates)); commandsSender.Start(); t.IsBackground = true; t.Start(); } }
/// <summary> /// Initializes a new instance of the <see cref="XInputDevice" /> class. /// </summary> /// <param name="deviceInfo">The device information.</param> public XInputDevice(XInputDeviceInfo deviceInfo) : base(deviceInfo) { // XInput devices don't lose acquisition when the application loses focus. IsAcquired = true; _info = deviceInfo; _controller = new XI.Controller(deviceInfo.ID); if (Axis.TryGetValue(GamingDeviceAxis.XAxis, out GorgonGamingDeviceAxis _)) { Axis[GamingDeviceAxis.XAxis].DeadZone = new GorgonRange(-XI.Gamepad.LeftThumbDeadZone, XI.Gamepad.LeftThumbDeadZone); } if (Axis.TryGetValue(GamingDeviceAxis.YAxis, out GorgonGamingDeviceAxis _)) { Axis[GamingDeviceAxis.YAxis].DeadZone = new GorgonRange(-XI.Gamepad.LeftThumbDeadZone, XI.Gamepad.LeftThumbDeadZone); } if ((deviceInfo.Capabilities & GamingDeviceCapabilityFlags.SupportsSecondaryXAxis) == GamingDeviceCapabilityFlags.SupportsSecondaryXAxis) { Axis[GamingDeviceAxis.XAxis2].DeadZone = new GorgonRange(-XI.Gamepad.RightThumbDeadZone, XI.Gamepad.RightThumbDeadZone); } if ((deviceInfo.Capabilities & GamingDeviceCapabilityFlags.SupportsSecondaryYAxis) == GamingDeviceCapabilityFlags.SupportsSecondaryYAxis) { Axis[GamingDeviceAxis.YAxis2].DeadZone = new GorgonRange(-XI.Gamepad.RightThumbDeadZone, XI.Gamepad.RightThumbDeadZone); } if ((deviceInfo.Capabilities & GamingDeviceCapabilityFlags.SupportsThrottle) == GamingDeviceCapabilityFlags.SupportsThrottle) { Axis[GamingDeviceAxis.RightTrigger].DeadZone = new GorgonRange(0, XI.Gamepad.TriggerThreshold); } if ((deviceInfo.Capabilities & GamingDeviceCapabilityFlags.SupportsRudder) == GamingDeviceCapabilityFlags.SupportsRudder) { Axis[GamingDeviceAxis.LeftTrigger].DeadZone = new GorgonRange(0, XI.Gamepad.TriggerThreshold); } }
/// <summary> /// Initializes a new instance of the <see cref="XInputController"/> class. /// </summary> /// <param name="owner">The input factory that owns this device.</param> /// <param name="joystickID">The ID of the joystick.</param> /// <param name="name">The name of the joystick.</param> /// <param name="controller">Controller instance to bind to this joystick.</param> internal XInputController(GorgonInputFactory owner, int joystickID, string name, XI.Controller controller) : base(owner, name) { AllowExclusiveMode = false; _controller = controller; _controllerID = joystickID; if (controller.IsConnected) { IsConnected = true; #if DEBUG XI.Capabilities caps = controller.GetCapabilities(XI.DeviceQueryType.Any); Gorgon.Log.Print("XInput XBOX 360 controller device {0} interface created (ID:{1}).", LoggingLevel.Simple, caps.SubType.ToString(), joystickID); #endif } else { Gorgon.Log.Print("Disconnected XInput XBOX 360 controller device #{0} interface created.", LoggingLevel.Simple, joystickID); IsConnected = false; } }
public XInputSceneController() { controller = new SharpDX.XInput.Controller(SharpDX.XInput.UserIndex.One); }
public void PollGamepad() { int WaitTimeAfterClick = 150; while (true) { if (controller == null) { FindController(1000); } else { if (controller.IsConnected) { if (IsButtonPressed(0, "GUIDE")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "GUIDE" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "DUP")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "DUP" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "DDOWN")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "DDOWN" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "DLEFT")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "DLEFT" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "DRIGHT")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "DRIGHT" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "START")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "START" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "BACK")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "BACK" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "LTHUMB")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "LTHUMB" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "RTHUMB")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "RTHUMB" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "LSHOULDER")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "LSHOULDER" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "RSHOULDER")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "RSHOULDER" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "A")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "A" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "B")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "B" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "X")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "X" }); Thread.Sleep(WaitTimeAfterClick); } if (IsButtonPressed(0, "Y")) { this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "Y" }); Thread.Sleep(WaitTimeAfterClick); } } else { controller = null; } } } }
/// <summary> /// Polls list of controller slots. /// </summary> /// <param name="timeout">timeout in milliseconds.</param> public bool FindController(int timeout) { Stopwatch stopwatch = null; if (timeout >= 0) { stopwatch = new Stopwatch(); stopwatch.Start(); } bool lookForController = (timeout >= -1); while (lookForController) { // Get 1st controller available foreach (var selectControler in controllers) { if (selectControler.IsConnected) { controller = selectControler; this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "CONTROLLER_CONNECTED" }); return true; } } if (stopwatch != null) { if (stopwatch.ElapsedMilliseconds > timeout) { lookForController = false; } } } this.iEventAggregator.GetEvent<PubSubEvent<ControllerEventArgs>>().Publish(new ControllerEventArgs { action = "CONTROLLER_NOT_FOUND" }); return false; }
public XInputGamePad(Controller instance, GamePadKey key) : base(key) { this.instance = instance; }
public Gamepad() { Controller = new SharpDX.XInput.Controller(UserIndex.One); }
public XInputController(SharpDX.XInput.Controller controller) { Controller = controller; }
/// <summary> /// Function to retrieve the capabilities of the xinput device. /// </summary> /// <param name="controller"></param> public void GetCaps(XI.Controller controller) { Capabilities = GamingDeviceCapabilityFlags.None; controller.GetCapabilities(XI.DeviceQueryType.Any, out XI.Capabilities capabilities); // Get vibration caps. var vibrationRanges = new List <GorgonRange>(); if (capabilities.Vibration.LeftMotorSpeed != 0) { vibrationRanges.Add(new GorgonRange(0, ushort.MaxValue)); Capabilities |= GamingDeviceCapabilityFlags.SupportsVibration; } if (capabilities.Vibration.RightMotorSpeed != 0) { vibrationRanges.Add(new GorgonRange(0, ushort.MaxValue)); Capabilities |= GamingDeviceCapabilityFlags.SupportsVibration; } VibrationMotorRanges = vibrationRanges; if (((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) || ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) || ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft) || ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight)) { Capabilities |= GamingDeviceCapabilityFlags.SupportsPOV; } // Get buttons, and remap to the button indices present in the gaming device control panel app. if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.A) == XI.GamepadButtonFlags.A) { SupportedButtons[XI.GamepadButtonFlags.A] = 0; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.B) == XI.GamepadButtonFlags.B) { SupportedButtons[XI.GamepadButtonFlags.B] = 1; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.X) == XI.GamepadButtonFlags.X) { SupportedButtons[XI.GamepadButtonFlags.X] = 2; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.Y) == XI.GamepadButtonFlags.Y) { SupportedButtons[XI.GamepadButtonFlags.Y] = 3; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.LeftShoulder) == XI.GamepadButtonFlags.LeftShoulder) { SupportedButtons[XI.GamepadButtonFlags.LeftShoulder] = 4; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.RightShoulder) == XI.GamepadButtonFlags.RightShoulder) { SupportedButtons[XI.GamepadButtonFlags.RightShoulder] = 5; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.Back) == XI.GamepadButtonFlags.Back) { SupportedButtons[XI.GamepadButtonFlags.Back] = 6; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.Start) == XI.GamepadButtonFlags.Start) { SupportedButtons[XI.GamepadButtonFlags.Start] = 7; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.LeftThumb) == XI.GamepadButtonFlags.LeftThumb) { SupportedButtons[XI.GamepadButtonFlags.LeftThumb] = 8; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.RightThumb) == XI.GamepadButtonFlags.RightThumb) { SupportedButtons[XI.GamepadButtonFlags.RightThumb] = 9; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) { SupportedButtons[XI.GamepadButtonFlags.DPadUp] = 10; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight) { SupportedButtons[XI.GamepadButtonFlags.DPadRight] = 11; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) { SupportedButtons[XI.GamepadButtonFlags.DPadDown] = 12; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft) { SupportedButtons[XI.GamepadButtonFlags.DPadLeft] = 13; } // Find out the ranges for each axis. var axes = new Dictionary <GamingDeviceAxis, GorgonRange>(new GorgonGamingDeviceAxisEqualityComparer()); if (capabilities.Gamepad.LeftThumbX != 0) { axes[GamingDeviceAxis.XAxis] = new GorgonRange(short.MinValue, short.MaxValue); } if (capabilities.Gamepad.LeftThumbY != 0) { axes[GamingDeviceAxis.YAxis] = new GorgonRange(short.MinValue, short.MaxValue); } if (capabilities.Gamepad.RightThumbX != 0) { axes[GamingDeviceAxis.XAxis2] = new GorgonRange(short.MinValue, short.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsSecondaryXAxis; } if (capabilities.Gamepad.RightThumbY != 0) { axes[GamingDeviceAxis.YAxis2] = new GorgonRange(short.MinValue, short.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsSecondaryYAxis; } if (capabilities.Gamepad.LeftTrigger != 0) { axes[GamingDeviceAxis.LeftTrigger] = new GorgonRange(0, byte.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsRudder; } if (capabilities.Gamepad.RightTrigger != 0) { axes[GamingDeviceAxis.RightTrigger] = new GorgonRange(0, byte.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsThrottle; } AxisInfo = new GorgonGamingDeviceAxisList <GorgonGamingDeviceAxisInfo>(axes.Select(item => new GorgonGamingDeviceAxisInfo(item.Key, item.Value, 0))); }
uint XInputGetCapabilities_Hooked(int dwUserIndex, DeviceQueryType dwFlags, out Capabilities pCapabilities) { pCapabilities = new Capabilities(); var controller = new Controller((UserIndex)dwUserIndex); if (controller.IsConnected) { try { pCapabilities = controller.GetCapabilities(dwFlags); } catch { return ERROR_DEVICE_NOT_CONNECTED; } } else { if ((UserIndex) dwUserIndex == UserIndex.One || (UserIndex) dwUserIndex == UserIndex.Any) { pCapabilities.Flags = CapabilityFlags.None; pCapabilities.Type = DeviceType.Gamepad; pCapabilities.SubType = DeviceSubType.Gamepad; pCapabilities.Gamepad.Buttons = GamepadButtonFlags.A | GamepadButtonFlags.B | GamepadButtonFlags.Back | GamepadButtonFlags.DPadDown | GamepadButtonFlags.DPadLeft | GamepadButtonFlags.DPadRight | GamepadButtonFlags.DPadUp | GamepadButtonFlags.LeftShoulder | GamepadButtonFlags.LeftThumb | GamepadButtonFlags.RightShoulder | GamepadButtonFlags.RightThumb | GamepadButtonFlags.Start | GamepadButtonFlags.X | GamepadButtonFlags.Y; pCapabilities.Gamepad.LeftTrigger = 0xFF; pCapabilities.Gamepad.RightTrigger = 0xFF; pCapabilities.Gamepad.LeftThumbX = short.MaxValue; pCapabilities.Gamepad.LeftThumbY = short.MaxValue; pCapabilities.Gamepad.RightThumbX = short.MaxValue; pCapabilities.Gamepad.RightThumbY = short.MaxValue; pCapabilities.Vibration.LeftMotorSpeed = 0xFF; pCapabilities.Vibration.RightMotorSpeed = 0xFF; } } return ERROR_SUCCESS; }
uint XInputGetDSoundAudioDeviceGuids_Hooked(int dwUserIndex, out Guid pDSoundRenderGuid, out Guid pDSoundCaptureGuid) { pDSoundRenderGuid = new Guid(); pDSoundCaptureGuid = new Guid(); var controller = new Controller((UserIndex)dwUserIndex); if (controller.IsConnected) { try { pDSoundRenderGuid = controller.SoundRenderGuid; pDSoundCaptureGuid = controller.SoundCaptureGuid; } catch { return ERROR_DEVICE_NOT_CONNECTED; } } return ERROR_SUCCESS; }
private void CaptureXInput() { var controller = new SXI.Controller((SXI.UserIndex)_joyInfo.XInputDevice); var inputState = controller.GetState(); bool[] axisMoved = { false, false, false, false, false, false, false, false }; //AXIS axisMoved[0] = GetAxisMovement(JoystickState.Axis[0], -inputState.Gamepad.LeftThumbY); axisMoved[1] = GetAxisMovement(JoystickState.Axis[1], inputState.Gamepad.LeftThumbX); axisMoved[2] = GetAxisMovement(JoystickState.Axis[2], -inputState.Gamepad.RightThumbY); axisMoved[3] = GetAxisMovement(JoystickState.Axis[3], inputState.Gamepad.RightThumbX); axisMoved[4] = GetAxisMovement(JoystickState.Axis[4], inputState.Gamepad.LeftTrigger * 129 < Joystick.Max_Axis ? inputState.Gamepad.LeftTrigger * 129 : Joystick.Max_Axis); axisMoved[5] = GetAxisMovement(JoystickState.Axis[5], inputState.Gamepad.RightTrigger * 129 < Joystick.Max_Axis ? inputState.Gamepad.RightTrigger * 129 : Joystick.Max_Axis); //POV Pov.Position previousPov = JoystickState.Povs[0].Direction; Pov.Position pov = Pov.Position.Centered; if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadUp) != 0) { pov |= Pov.Position.North; } else if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadDown) != 0) { pov |= Pov.Position.South; } if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadLeft) != 0) { pov |= Pov.Position.West; } else if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadRight) != 0) { pov |= Pov.Position.East; } JoystickState.Povs[0].Direction = pov; //BUTTONS // Skip the first 4 as they are the DPad. var previousButtons = JoystickState.Buttons; for (int i = 0; i < 12; i++) { if (((int)inputState.Gamepad.Buttons & (1 << (i + 4))) != 0) { JoystickState.Buttons |= 1 << (i + 4); } else { JoystickState.Buttons &= ~(1 << (i + 4)); } } //Send Events if (IsBuffered && EventListener != null) { var joystickEvent = new JoystickEventArgs(this, JoystickState); // Axes for (int index = 0; index < axisMoved.Length; index++) { if (axisMoved[index] == true && EventListener.AxisMoved(joystickEvent, index)) { return; } } //POV if (previousPov != pov && !EventListener.PovMoved(joystickEvent, 0)) { return; } //Buttons for (int i = 4; i < 16; i++) { if (((previousButtons & (1 << i)) == 0) && JoystickState.IsButtonDown(i)) { if (!EventListener.ButtonPressed(joystickEvent, i)) { return; } } else if (((previousButtons & (1 << i)) != 0) && !JoystickState.IsButtonDown(i)) { if (!EventListener.ButtonReleased(joystickEvent, i)) { return; } } } } }
/// <summary> /// ctor and init /// </summary> /// <param name="device">A DXInput device</param> /// <param name="hwnd">The WinHandle of the main window</param> /// <param name="panel">The respective JS panel to show the properties</param> public GamepadCls(SharpDX.XInput.Controller device, UC_GpadPanel panel, int tabIndex) { log.DebugFormat("GamepadCls ctor - Entry with index {0}", device.ToString( )); m_device = device; m_gPanel = panel; MyTabPageIndex = tabIndex; Activated = false; m_senseLimit = AppConfiguration.AppConfig.gpSenseLimit; // can be changed in the app.config file if it is still too little // Set BufferSize in order to use buffered data. log.Debug("Get GP Objects"); try { m_gpCaps = m_device.GetCapabilities(DeviceQueryType.Gamepad); } catch (Exception ex) { log.Error("Get GamepadCapabilities failed", ex); } m_gPanel.Caption = DevName; int n = 0; if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadDown)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadLeft)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadRight)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadUp)) { n++; } m_gPanel.nDPads = n.ToString( ); m_gPanel.DPadE = (n > 0); n = 0; if ((m_gpCaps.Gamepad.LeftThumbX != 0) || (m_gpCaps.Gamepad.LeftThumbY != 0) || Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.LeftThumb)) { n++; m_gPanel.TStickLE = true; } if ((m_gpCaps.Gamepad.RightThumbX != 0) || (m_gpCaps.Gamepad.RightThumbY != 0) || Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.RightThumb)) { n++; m_gPanel.TStickRE = true; } m_gPanel.nTSticks = n.ToString( ); n = 0; if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.A)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.B)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.X)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Y)) { n++; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Start)) { n++; m_gPanel.StartE = true; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Back)) { n++; m_gPanel.BackE = true; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.LeftShoulder)) { n++; m_gPanel.ShoulderLE = true; } if (Bit(m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.RightShoulder)) { n++; m_gPanel.ShoulderRE = true; } m_gPanel.nButtons = n.ToString( ); n = 0; if (m_gpCaps.Gamepad.LeftTrigger > 0) { n++; m_gPanel.TriggerLE = true; } if (m_gpCaps.Gamepad.RightTrigger > 0) { n++; m_gPanel.TriggerRE = true; } m_gPanel.nTriggers = n.ToString( ); m_gPanel.ButtonE = true; // what else ... ApplySettings( ); // get whatever is needed here from Settings Activated = true; }
/// <summary> /// Initializes a new instance of the <see cref="GamePad"/> class. /// </summary> public GamePad() : base(UPDATE_TIMEOUT) { controller = new SharpDX.XInput.Controller(UserIndex.One); connected = controller.IsConnected; }
public GamepadState(UserIndex userIndex) { UserIndex = userIndex; Controller = new Controller(userIndex); }
private void connectController() { _controller = new Controller(UserIndex.One); }
public override void Dispose() { instance = null; }
public GamepadContext() { controller = new Controller(UserIndex.One); SetCurrentState(); SetPreviousState(); }
public XInputController() { this.controller = new SharpDX.XInput.Controller(UserIndex.One); }
//call this on call back when something is beeing plugged in or unplugged public void InitializeJoystickIfPossible() { m_joystick = new SharpDX.XInput.Controller(SharpDX.XInput.UserIndex.One); if (JoystickConnected != null) { JoystickConnected(m_joystick.IsConnected); } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonXInputDeviceInfo"/> class. /// </summary> /// <param name="name">The device name.</param> /// <param name="hidPath">Human interface device path.</param> /// <param name="controller">Controller interface.</param> /// <param name="index">Index of the controller.</param> /// <exception cref="System.ArgumentNullException">Either the name, className or hidPath are NULL or empty.</exception> public GorgonXInputDeviceInfo(string name, string hidPath, XI.Controller controller, int index) : base(name, InputDeviceType.Joystick, "disconnected controller", hidPath) { Controller = controller; Index = index; }