当前位置: 首页>>代码示例>>C#>>正文


C# Joystick.GetObjects方法代码示例

本文整理汇总了C#中Joystick.GetObjects方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.GetObjects方法的具体用法?C# Joystick.GetObjects怎么用?C# Joystick.GetObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Joystick的用法示例。


在下文中一共展示了Joystick.GetObjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GamePadDevice

        /// <summary>
        /// 番号指定でデバイス生成。番号のデバイスが存在しなければ例外を投げる。
        /// </summary>
        /// <param name="window"></param>
        /// <param name="padNumber">0始まり</param>
        public GamePadDevice(int padNumber, DirectInput directInput)
        {
            var devices = GetDevices(directInput);
            if (devices.Count <= padNumber)
            {
                throw new Exception("指定された数のパッドがつながれていない");
            }
            try
            {
                Stick = new Joystick(directInput, devices[padNumber].InstanceGuid);
                //Stick.SetCooperativeLevel(window, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
            }
            catch (Exception e)
            {
                throw new Exception("パッドの初期化に失敗", e);
            }

            ///スティックの範囲設定
            foreach (var item in Stick.GetObjects())
            {
                //if ((item.ObjectType & .Axis) != 0)
                //{
                //	Stick.GetObjectPropertiesById((int)item.ObjectType).SetRange(-1000, 1000);
                //}

            }
            Stick.Acquire();
        }
开发者ID:MasakiMuto,项目名称:MasaLibs,代码行数:33,代码来源:GamePadDevice.cs

示例2: Initialize

		public static void Initialize()
		{
			if (dinput == null)
				dinput = new DirectInput();

			Devices = new List<GamePad>();

			foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
			{
				Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName);

				if (device.ProductName.Contains("XBOX 360"))
					continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput)

				var joystick = new Joystick(dinput, device.InstanceGuid);
				joystick.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
				foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
				{
					if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
						joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
				}
				joystick.Acquire();

				GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick);
				Devices.Add(p);
			}
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:27,代码来源:GamePad.cs

示例3: GetJoystick

        private Joystick GetJoystick()
        {
            var directInput = new DirectInput();
            var form = new Form();

            foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                var controller = new Joystick(directInput, device.InstanceGuid);
                controller.SetCooperativeLevel(form.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);

                var retries = 0;
                while (controller.Acquire().IsFailure)
                {
                    retries++;
                    if (retries > 500)
                        throw new Exception("Couldnt acquire SlimDX stick");
                }

                if (controller.Information.InstanceName.Contains("PPJoy"))
                {

                    foreach (DeviceObjectInstance deviceObject in controller.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                            controller.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                    }

                    return controller;
                }
            }

            return null;
        }
开发者ID:Cyborg11,项目名称:FreePIE,代码行数:33,代码来源:PPJoyPluginTest.cs

示例4: GamepadReader

        public GamepadReader()
        {
            Buttons = _buttons;
            Analogs = _analogs;

            _dinput = new DirectInput();

            var devices = _dinput.GetDevices (DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
            if (devices.Count < 1) {
                throw new IOException ("GamepadReader could not find a connected gamepad.");
            }
            _joystick = new Joystick (_dinput, devices[0].InstanceGuid);

            foreach (var obj in _joystick.GetObjects()) {
                if ((obj.ObjectType & ObjectDeviceType.Axis) != 0) {
                    _joystick.GetObjectPropertiesById ((int)obj.ObjectType).SetRange (-RANGE, RANGE);
                }
            }

            if (_joystick.Acquire().IsFailure) {
                throw new IOException ("Connected gamepad could not be acquired.");
            }

            _timer = new DispatcherTimer ();
            _timer.Interval = TimeSpan.FromMilliseconds (TIMER_MS);
            _timer.Tick += tick;
            _timer.Start ();
        }
开发者ID:Karl-Parris,项目名称:NintendoSpy,代码行数:28,代码来源:GamepadReader.cs

示例5: MainController

        public MainController()
        {
            var directInput = new DirectInput();
            LogicState = new LogicState();

            foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    gamepad = new Joystick(directInput, deviceInstance.InstanceGuid);
                    gamepad.SetCooperativeLevel(Parent, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException) { }
            }

            if (gamepad == null)
                return;

            foreach (var deviceObject in gamepad.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    gamepad.GetObjectPropertiesById((int) deviceObject.ObjectType).SetRange(-1000, 1000);
            }

            gamepad.Acquire();
        }
开发者ID:martikaljuve,项目名称:Robin,代码行数:27,代码来源:MainController.cs

示例6: GetDeviceObjects

 public static DeviceObjectItem[] GetDeviceObjects(Joystick device)
 {
     var og = typeof(SharpDX.DirectInput.ObjectGuid);
     var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid));
     List<Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList();
     List<string> names = guidFileds.Select(x => x.Name).ToList();
     var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray();
     var items = new List<DeviceObjectItem>();
     foreach (var o in objects)
     {
         var item = new DeviceObjectItem()
         {
             Name = o.Name,
             Offset = o.Offset,
             Instance = o.ObjectId.InstanceNumber,
             Usage = o.Usage,
             Aspect = o.Aspect,
             Flags = o.ObjectId.Flags,
             GuidValue = o.ObjectType,
             GuidName = guids.Contains(o.ObjectType) ? names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(),
         };
         items.Add(item);
     }
     return items.ToArray();
 }
开发者ID:Grommini,项目名称:x360ce,代码行数:25,代码来源:AppHelper.cs

示例7: SimpleJoystick

        /// 
        /// Construct, attach the joystick
        /// 
        public SimpleJoystick()
        {
            DirectInput dinput = new DirectInput();

            // Search for device
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // Create device
                try
                {
                    Joystick = new Joystick(dinput, device.InstanceGuid);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (Joystick == null)
                throw new Exception("No joystick found");

            foreach (DeviceObjectInstance deviceObject in Joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    Joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
            }

            // Acquire sdevice
            Joystick.Acquire();
        }
开发者ID:wariw,项目名称:360Joypad_test,代码行数:33,代码来源:SimpleJoystick.cs

示例8: Acquire

        public void Acquire(Form parent)
        {
            var dinput = new DirectInput();

            Pad = new Joystick(dinput, Guid);
            foreach (DeviceObjectInstance doi in Pad.GetObjects(ObjectDeviceType.Axis))
            {
                Pad.GetObjectPropertiesById((int) doi.ObjectType).SetRange(-5000, 5000);
            }

            Pad.Properties.AxisMode = DeviceAxisMode.Absolute;
            Pad.SetCooperativeLevel(parent, (CooperativeLevel.Nonexclusive | CooperativeLevel.Background));
            ButtonCount = Pad.Capabilities.ButtonCount;
            Pad.Acquire();
        }
开发者ID:tobig82,项目名称:iRduino,代码行数:15,代码来源:ControllerDevice.cs

示例9: InputDeviceImp

        /// <summary>
        /// Initializes a new instance of the <see cref="InputDeviceImp"/> class.
        /// </summary>
        /// <param name="instance">The DeviceInstance.</param>
        public InputDeviceImp(DeviceInstance instance)
        {
            _controller = instance;
            _deadZone = 0.1f;
            buttonsPressed = new bool[100];
            _joystick = new Joystick(new DirectInput(), _controller.InstanceGuid);

            foreach (DeviceObjectInstance deviceObject in _joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    _joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);

            }

            _joystick.Acquire();
        }
开发者ID:GameProduction,项目名称:ScharfschiessenGame,代码行数:20,代码来源:InputDeviceImp.cs

示例10: CreateDevice

        void CreateDevice()
        {
            // make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    joystick.SetCooperativeLevel(this, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (joystick == null)
            {
                MessageBox.Show("There are no joysticks attached to the system.");
                return;
            }

            foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);

                UpdateControl(deviceObject);
            }

            // acquire the device
            joystick.Acquire();

            // set the timer to go off 12 times a second to read input
            // NOTE: Normally applications would read this much faster.
            // This rate is for demonstration purposes only.
            timer.Interval = 1000 / 12;
            timer.Start();
        }
开发者ID:zhandb,项目名称:slimdx,代码行数:43,代码来源:MainForm.cs

示例11: GetSticks

        // --- INITIALIZTION ---

        public int GetSticks(IMatchDisplay form)
        {
            _form = form;
            DirectInput Input = new DirectInput();

            List<Joystick> sticks = new List<Joystick>(); // Creates the list of joysticks connected to the computer via USB.
            foreach (DeviceInstance device in Input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // Creates a joystick for each game device in USB Ports
                try
                {
                    var stick = new Joystick(Input, device.InstanceGuid);
                    stick.Acquire();

                    // Gets the joysticks properties and sets the range for them.
                    foreach (DeviceObjectInstance deviceObject in stick.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                            stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
                    }

                    // Adds how ever many joysticks are connected to the computer into the sticks list.
                    sticks.Add(stick);
                }
                catch (DirectInputException)
                {
                }
            }
            Sticks = sticks.ToArray();
            var count = Sticks.Length;
            if (count > 0)
            {
                tm1939LoadSticks();
            }
            return count; // sticks.ToArray();
        }
开发者ID:FIRST1939,项目名称:2016ScoutingSystem,代码行数:38,代码来源:GameInput.cs

示例12: CreateDevice

        private void CreateDevice(int idGamepad)
        {
            // make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();

            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    //joystick.SetCooperativeLevel(windowHandle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    if (joystick.Properties.JoystickId == idGamepad)
                        break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (joystick == null)
            {
                //throw new Exception("There are no joysticks attached to the system.");
                MessageBox.Show("There are no joysticks attached to the system.");                
                return;
            }

            foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);

                //UpdateControl(deviceObject);
            }

            joystick.Acquire();
        }
开发者ID:FACE-Team,项目名称:FACETools,代码行数:36,代码来源:GamepadController.xaml.cs

示例13: Initialize

        public override void Initialize()
        {
            buttonDown = -1;
            joystickIsReady = false;

            // Make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();
            state = new JoystickState();

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    joystick.SetCooperativeLevel(Core.Settings.RenderForm.Handle,
                        CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (joystick != null)
            {
                foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
                {
                    if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                        joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                }
            }
            else
            {
                return;
            }

            // acquire the device
            joystick.Acquire();

            timer = new Timer();
            timer.Interval = 1000 / 10;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }
开发者ID:zulis,项目名称:Cubica,代码行数:46,代码来源:JoyStick.cs

示例14: ShowDeviceInfo

 void ShowDeviceInfo(Joystick device)
 {
     if (device == null)
     {
         // clean everything here.
         SetValue(DeviceProductNameTextBox, "");
         SetValue(DeviceProductGuidTextBox, "");
         SetValue(DeviceInstanceGuidTextBox, "");
         DiCapFfStateTextBox.Text = string.Empty;
         DiCapAxesTextBox.Text = string.Empty;
         DiCapButtonsTextBox.Text = string.Empty;
         DiCapDPadsTextBox.Text = string.Empty;
         DiEffectsTable.Rows.Clear();
         return;
     }
     lock (MainForm.XInputLock)
     {
         var isLoaded = XInput.IsLoaded;
         if (isLoaded) XInput.FreeLibrary();
         device.Unacquire();
         device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
         effects = new List<EffectInfo>();
         try
         {
             device.Acquire();
             var forceFeedback = device.Capabilities.Flags.HasFlag(DeviceFlags.ForceFeedback);
             forceFeedbackState = forceFeedback ? "YES" : "NO";
             effects = device.GetEffects(EffectType.All);
         }
         catch (Exception)
         {
             forceFeedbackState = "ERROR";
         }
         DiEffectsTable.Rows.Clear();
         foreach (var eff in effects)
         {
             DiEffectsTable.Rows.Add(new object[]{
                         eff.Name,
                         ((EffectParameterFlags)eff.StaticParameters).ToString(),
                         ((EffectParameterFlags)eff.DynamicParameters).ToString()
                     });
         }
         device.Unacquire();
         device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
         if (isLoaded)
         {
             Exception error;
             XInput.ReLoadLibrary(XInput.LibraryName, out error);
         }
     }
     DiCapFfStateTextBox.Text = forceFeedbackState;
     DiCapButtonsTextBox.Text = device.Capabilities.ButtonCount.ToString();
     DiCapDPadsTextBox.Text = device.Capabilities.PovCount.ToString();
     var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray();
     DiObjectsTable.Rows.Clear();
     var og = typeof(SharpDX.DirectInput.ObjectGuid);
     var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid));
     List<Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList();
     List<string> names = guidFileds.Select(x => x.Name).ToList();
     foreach (var o in objects)
     {
         DiObjectsTable.Rows.Add(new object[]{
                         o.Offset,
                         o.ObjectId.InstanceNumber,
                         o.Usage,
                         o.Name,
                         o.Aspect,
                         guids.Contains(o.ObjectType) ?  names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(),
                         o.ObjectId.Flags,
                     });
     }
     var actuators = objects.Where(x => x.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator));
     ActuatorsTextBox.Text = actuators.Count().ToString();
     var di = device.Information;
     var slidersCount = objects.Where(x => x.ObjectType.Equals(SharpDX.DirectInput.ObjectGuid.Slider)).Count();
     DiCapAxesTextBox.Text = (device.Capabilities.AxeCount - slidersCount).ToString();
     SlidersTextBox.Text = slidersCount.ToString();
     // Update PID and VID always so they wont be overwritten by load settings.
     short vid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 0);
     short pid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 2);
     SetValue(DeviceVidTextBox, "0x{0}", vid.ToString("X4"));
     SetValue(DevicePidTextBox, "0x{0}", pid.ToString("X4"));
     SetValue(DeviceProductNameTextBox, di.ProductName);
     SetValue(DeviceProductGuidTextBox, di.ProductGuid.ToString());
     SetValue(DeviceInstanceGuidTextBox, di.InstanceGuid.ToString());
     SetValue(DeviceTypeTextBox, di.Type.ToString());
 }
开发者ID:suvjunmd,项目名称:x360ce,代码行数:87,代码来源:DirectInputControl.cs

示例15: CreateDevice

        void CreateDevice()
        {
            // make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    //joystick.SetCooperativeLevel(this, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (joystick == null)
            {
                LogMessage("There are no joysticks attached to the system.");
                LogMessage("Restart application after connecting stick.");
                return;
            }

            foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
            }

            // acquire the device
            joystick.Acquire();
        }
开发者ID:jwalthour,项目名称:wamp,代码行数:36,代码来源:MainWindow.xaml.cs


注:本文中的Joystick.GetObjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。