public static unsafe int XInputGetCapabilities(int dwUserIndex, DeviceQueryType dwFlags, out Capabilities capabilitiesRef) { capabilitiesRef = new Capabilities(); int capabilities; fixed (Capabilities* capabilitiesPtr = &capabilitiesRef) capabilities = XInput.XInputGetCapabilities_(dwUserIndex, (int) dwFlags, (void*) capabilitiesPtr); return capabilities; }
/// <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="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; } }
/// <summary> /// Function to poll the joystick for data. /// </summary> protected override void PollJoystick() { if (!_controller.IsConnected) { Gorgon.Log.Print("XInput Controller {0} disconnected.", LoggingLevel.Verbose, _controllerID); IsConnected = false; return; } // If we weren't connected before, then get the caps for the device. if (!IsConnected) { var previousDeadZone = DeadZone; Initialize(); IsConnected = true; // Restore the dead zone. DeadZone.Rudder = new GorgonRange(previousDeadZone.Rudder); DeadZone.Throttle = new GorgonRange(previousDeadZone.Throttle); DeadZone.X = new GorgonRange(previousDeadZone.X); DeadZone.Y = new GorgonRange(previousDeadZone.Y); DeadZone.SecondaryX = new GorgonRange(previousDeadZone.SecondaryX); DeadZone.SecondaryY = new GorgonRange(previousDeadZone.SecondaryY); #if DEBUG XI.Capabilities caps = _controller.GetCapabilities(XI.DeviceQueryType.Any); Gorgon.Log.Print("XInput Controller {0} (ID:{1}) re-connected.", LoggingLevel.Verbose, caps.SubType.ToString(), _controllerID); #endif } XI.State state = _controller.GetState(); // Do nothing if the data has not changed since the last poll. if (LastPacket == state.PacketNumber) { return; } // Get axis data. X = state.Gamepad.LeftThumbX; Y = state.Gamepad.LeftThumbY; SecondaryX = state.Gamepad.RightThumbX; SecondaryY = state.Gamepad.RightThumbY; Throttle = state.Gamepad.RightTrigger; Rudder = state.Gamepad.LeftTrigger; // Get button info. if (state.Gamepad.Buttons != XI.GamepadButtonFlags.None) { // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < _button.Length; i++) { _buttonList.SetButtonState(_button[i], (_button[i] != XI.GamepadButtonFlags.None) && ((state.Gamepad.Buttons & _button[i]) == _button[i])); } } // Get POV values. GetPOVData(state.Gamepad.Buttons); }
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; }
public static extern int XInputGetCapabilities(int dwUserIndex, DeviceQueryType dwFlags, out Capabilities capabilitiesRef);
public int XInputGetCapabilities(int dwUserIndex, DeviceQueryType dwFlags, out Capabilities capabilitiesRef) { return Native.XInputGetCapabilities(dwUserIndex, dwFlags, out capabilitiesRef); }
public static GamePadCapabilities GetCapabilities(PlayerIndex playerIndex) { Controller controller = GamePad.GetController(playerIndex); if (!controller.IsConnected) { return(new GamePadCapabilities()); } SharpDX.XInput.Capabilities capabilities = controller.GetCapabilities(DeviceQueryType.Any); GamePadCapabilities gamePadCapabilities = new GamePadCapabilities(); switch (capabilities.SubType) { case DeviceSubType.Gamepad: gamePadCapabilities.GamePadType = GamePadType.GamePad; break; case DeviceSubType.Wheel: gamePadCapabilities.GamePadType = GamePadType.Wheel; break; case DeviceSubType.ArcadeStick: gamePadCapabilities.GamePadType = GamePadType.ArcadeStick; break; case DeviceSubType.DancePad: gamePadCapabilities.GamePadType = GamePadType.DancePad; break; case DeviceSubType.Guitar: gamePadCapabilities.GamePadType = GamePadType.Guitar; break; case DeviceSubType.DrumKit: gamePadCapabilities.GamePadType = GamePadType.DrumKit; break; default: gamePadCapabilities.GamePadType = GamePadType.Unknown; break; } Gamepad gamepad = capabilities.Gamepad; GamepadButtonFlags gamepadButtonFlags = gamepad.Buttons; gamePadCapabilities.HasAButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.A); gamePadCapabilities.HasBackButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.Back); gamePadCapabilities.HasBButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.B); gamePadCapabilities.HasBigButton = false; gamePadCapabilities.HasDPadDownButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadDown); gamePadCapabilities.HasDPadLeftButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadLeft); gamePadCapabilities.HasDPadRightButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadLeft); gamePadCapabilities.HasDPadUpButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadUp); gamePadCapabilities.HasLeftShoulderButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.LeftShoulder); gamePadCapabilities.HasLeftStickButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.LeftThumb); gamePadCapabilities.HasRightShoulderButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.RightShoulder); gamePadCapabilities.HasRightStickButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.RightThumb); gamePadCapabilities.HasStartButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.Start); gamePadCapabilities.HasXButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.X); gamePadCapabilities.HasYButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.Y); gamePadCapabilities.HasRightTrigger = (int)gamepad.LeftTrigger > 0; gamePadCapabilities.HasRightXThumbStick = (int)gamepad.RightThumbX != 0; gamePadCapabilities.HasRightYThumbStick = (int)gamepad.RightThumbY != 0; gamePadCapabilities.HasLeftTrigger = (int)gamepad.LeftTrigger > 0; gamePadCapabilities.HasLeftXThumbStick = (int)gamepad.LeftThumbX != 0; gamePadCapabilities.HasLeftYThumbStick = (int)gamepad.LeftThumbY != 0; gamePadCapabilities.HasLeftVibrationMotor = (int)capabilities.Vibration.LeftMotorSpeed > 0; gamePadCapabilities.HasRightVibrationMotor = (int)capabilities.Vibration.RightMotorSpeed > 0; gamePadCapabilities.IsConnected = controller.IsConnected; gamePadCapabilities.HasVoiceSupport = capabilities.Flags.HasFlag((Enum)CapabilityFlags.VoiceSupported); return(gamePadCapabilities); }
/// <summary> /// Gets the capabilities. /// </summary> /// <param name="deviceQueryType">Type of the device query.</param> /// <param name="capabilities">The capabilities of this controller.</param> /// <returns><c>true</c> if the controller is connected, <c>false</c> otherwise.</returns> public bool GetCapabilities(DeviceQueryType deviceQueryType, out Capabilities capabilities) { return XInput.XInputGetCapabilities((int)userIndex, deviceQueryType, out capabilities) == 0; }
public int XInputGetCapabilities(int dwUserIndex, DeviceQueryType dwFlags, out Capabilities capabilitiesRef) { return(Native.XInputGetCapabilities(dwUserIndex, dwFlags, out capabilitiesRef)); }
/// <summary> /// Gets the capabilities. /// </summary> /// <param name="deviceQueryType">Type of the device query.</param> /// <param name="capabilities">The capabilities of this controller.</param> /// <returns><c>true</c> if the controller is connected, <c>false</c> otherwise.</returns> public bool GetCapabilities(DeviceQueryType deviceQueryType, out Capabilities capabilities) { return(xinput.XInputGetCapabilities((int)userIndex, deviceQueryType, out capabilities) == 0); }