예제 #1
0
        /// <summary>
        /// Найти все устройства типа джойстик
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            try
            {
                _quitThread = false;
                // create a device from this controller.
                _joystick = new SlimDX.DirectInput.Joystick(_directInput, _deviceInstance.InstanceGuid);

                foreach (var doi in _joystick.GetObjects(ObjectDeviceType.Axis))
                {
                    _joystick.GetObjectPropertiesById((int)doi.ObjectType).SetRange(MinimumAxisValue, MaximumAxisValue);
                }
                _joystick.Properties.AxisMode = DeviceAxisMode.Absolute;

                _joystick.SetCooperativeLevel(IntPtr.Zero, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
                // Tell DirectX that this is a Joystick.
                //            _joystick.SetDataFormat(DeviceDataFormat.Joystick);

                _joystickThread = new Thread(GetJoystickData);
                _joystick.SetNotification(_joystickEvent);
                // Finally, acquire the device.
                _buttons = new bool[_joystick.GetObjects(ObjectDeviceType.Button).Count];
                _axis    = new int[/*_joystick.GetObjects(ObjectDeviceType.Axis).Count+3*/ 128];
                //            PointOfView = new int[caps.NumberPointOfViews];
                _joystick.Acquire();

                _joystickThread.Start();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #2
0
        private SlimDX.DirectInput.Joystick _CreateDevice()
        {
            SlimDX.DirectInput.Joystick device;

            using (DirectInput directInput = new DirectInput()) {
                // Try to get the device specified.
                DeviceInstance deviceInstance =
                    directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).FirstOrDefault(
                        x => x.InstanceGuid == DeviceId);

                if (deviceInstance == null)
                {
                    throw new Exception("Specified joystick not found.");
                }

                device = new SlimDX.DirectInput.Joystick(directInput, deviceInstance.InstanceGuid);
                // This needs System.Windows.Forms.Control.
                device.SetCooperativeLevel(IntPtr.Zero, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
                device.Properties.SetRange((int)Position.MinValue, (int)Position.MaxValue);

                Inputs = _GetInputs(device).ToArray();
            }

            return(device);
        }
예제 #3
0
        private static bool CreateController()
        {
            if (DXJoystick != null)
            {
                return(true);
            }
            int num = 1;

            foreach (var device in DirectInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                if (num == 1)
                {
                    DXJoystick = new DXJoystick(DirectInput, device.InstanceGuid);
                    Application.Current.Dispatcher.Invoke(() => {
                        try
                        {
                            DXJoystick.SetCooperativeLevel(new WindowInteropHelper(Application.Current.MainWindow).Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
                        }
                        catch { }
                    });
                    break;
                }
                ++num;
            }
            if (DXJoystick != null)
            {
                foreach (var deviceObjectInstance in DXJoystick.GetObjects())
                {
                    if ((uint)(deviceObjectInstance.ObjectType & ObjectDeviceType.Axis) > 0U)
                    {
                        DXJoystick.GetObjectPropertiesById((int)deviceObjectInstance.ObjectType).SetRange(-1000, 1000);
                    }
                }
            }
            return(DXJoystick != null);
        }
예제 #4
0
파일: Joystick.cs 프로젝트: stewmc/vixen
		private SlimDX.DirectInput.Joystick _CreateDevice()
		{
			SlimDX.DirectInput.Joystick device;

			using (DirectInput directInput = new DirectInput()) {
				// Try to get the device specified.
				DeviceInstance deviceInstance =
					directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).FirstOrDefault(
						x => x.InstanceGuid == DeviceId);

				if (deviceInstance == null) {
					throw new Exception("Specified joystick not found.");
				}

				device = new SlimDX.DirectInput.Joystick(directInput, deviceInstance.InstanceGuid);
				// This needs System.Windows.Forms.Control.
				device.SetCooperativeLevel(IntPtr.Zero, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
				device.Properties.SetRange((int) Position.MinValue, (int) Position.MaxValue);

				Inputs = _GetInputs(device).ToArray();
			}

			return device;
		}