示例#1
0
        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);
        }
示例#2
0
        private IEnumerable <ILowLevelInputDevice> GetGenericGamepads(IEnumerable <DeviceInstance> gamepads,
                                                                      SharpDX.DirectInput.DirectInput directInput)
        {
            var inputDevices = new List <ILowLevelInputDevice>();

            for (int i = 0; i < gamepads.Count(); i++)
            {
                DeviceInstance             deviceInstance = gamepads.ElementAt(i);
                SharpDX.DirectInput.Device device         = new Joystick(directInput, deviceInstance.InstanceGuid);

                var inputDevice = new LowLevelInputDevice()
                {
                    DiscoveryApi         = InputApi.DirectInput,
                    DI_InstanceGUID      = deviceInstance.InstanceGuid,
                    DI_InstanceName      = deviceInstance.InstanceName.Trim('\0'),
                    DI_ProductName       = deviceInstance.ProductName.Trim('\0'),
                    DI_ProductGUID       = deviceInstance.ProductGuid,
                    DI_DeviceType        = DeviceType.Gamepad,
                    DI_EnumerationNumber = i,
                };

                try
                {
                    inputDevice.DI_InterfacePath = device.Properties.InterfacePath.Trim('\0');
                    inputDevice.DI_JoystickID    = device.Properties.JoystickId;
                    inputDevice.DI_ProductID     = device.Properties.ProductId;
                    inputDevice.DI_VendorID      = device.Properties.VendorId;
                }
                catch (SharpDXException)
                {
                    inputDevice.DI_JoystickID    = null;
                    inputDevice.DI_InterfacePath = null;
                }
                finally
                {
                    inputDevices.Add(inputDevice);
                }
            }

            return(inputDevices);
        }