コード例 #1
0
        /// <summary>
        /// Enum all controllers
        /// </summary>
        /// <returns></returns>
        public override IEnumerable<IController> EnumControlls()
        {
            //List<IController> joysticks = this.EnumControlls();
            //List<IController> keyboards = this.EnumControlls();
            //List<IController> all = new List<IController>();
            //all.AddRange(joysticks);
            //all.AddRange(keyboards);
            //return all;

            m_controllers.Clear();
            try {
                foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.All, EnumDevicesFlags.AttachedOnly)) {
                    IController c = null;
                    if (di.DeviceType == DeviceType.Gamepad || di.DeviceType == DeviceType.Joystick)
                        c = new DXJoystickController(di.InstanceGuid);
                    else if (di.DeviceType == DeviceType.Keyboard)
                        c = new DXKeyboardController(di.InstanceGuid);
                    else
                        continue;

                    m_controllers.Add(di.InstanceGuid, c);
                }
            } catch (Exception err) {
                System.Diagnostics.Trace.TraceWarning(err.Message);
            }
            return m_controllers.Values;
        }
コード例 #2
0
 /// <summary>
 /// Enum all keyboard controllers.
 /// </summary>
 /// <returns></returns>
 public List<IController> EnumKeyboards()
 {
     List<IController> controllers = new List<IController>();
     m_keyboards.Clear();
     try {
         foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly)) {
             IController c = new DXKeyboardController(di.InstanceGuid);
             controllers.Add(c);
             m_keyboards.Add(di.InstanceGuid, c);
         }
     } catch (Exception err) {
         System.Diagnostics.Trace.TraceWarning(err.Message);
     }
     return controllers;
 }