Ejemplo n.º 1
0
        public IEnumerable <IHostDeviceInfo> GetAvailableJoysticks()
        {
            var list = new List <IHostDeviceInfo>();

            try
            {
                using (var di = new DirectInput8W())
                {
                    var devList = di.EnumDevices(DI8DEVCLASS.GAMECTRL, DIEDFL.ATTACHEDONLY);
                    foreach (var deviceInstance in devList)
                    {
                        var hdi = new HostDeviceInfo(
                            deviceInstance.tszInstanceName,
                            GetDeviceId(deviceInstance.guidInstance));
                        list.Add(hdi);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            list.Sort();
            list.Insert(
                0,
                new HostDeviceInfo("Keyboard Numpad", KeyboardNumpadId));
            list.Insert(
                0,
                new HostDeviceInfo("None", string.Empty));
            return(list);
        }
Ejemplo n.º 2
0
        public IEnumerable <IHostDeviceInfo> GetAvailableJoysticks()
        {
            var list = new List <IHostDeviceInfo>();

            try
            {
                var devList = Manager.GetDevices(
                    DeviceClass.GameControl,
                    EnumDevicesFlags.AttachedOnly);
                while (devList.MoveNext())
                {
                    var deviceInstance = (DeviceInstance)devList.Current;
                    var hdi            = new HostDeviceInfo(
                        deviceInstance.InstanceName,
                        GetDeviceId(deviceInstance.InstanceGuid));
                    list.Add(hdi);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            list.Sort();
            list.Insert(
                0,
                new HostDeviceInfo("Keyboard Numpad", KeyboardNumpadId));
            list.Insert(
                0,
                new HostDeviceInfo("None", string.Empty));
            return(list);
        }