Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
		public void Acquire()
		{
			if (!IsAcquired) {
				_waitHandle = new AutoResetEvent(false);
				_device = _CreateDevice();
				// Must be done before acquisition.
				_device.SetNotification(_waitHandle);
				_device.Acquire();
				// Must be set before any notifications come through.
				IsAcquired = true;
				Thread thread = new Thread(_UpdateThread) {Name = "Joystick"};
				thread.Start();
			}
		}
Exemplo n.º 3
0
 public void Acquire()
 {
     if (!IsAcquired)
     {
         _waitHandle = new AutoResetEvent(false);
         _device     = _CreateDevice();
         // Must be done before acquisition.
         _device.SetNotification(_waitHandle);
         _device.Acquire();
         // Must be set before any notifications come through.
         IsAcquired = true;
         Thread thread = new Thread(_UpdateThread)
         {
             Name = "Joystick"
         };
         thread.Start();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor, do the following to loop through and select your joystick
        /// SlimDX.DirectInput.DirectInput dinput = new SlimDX.DirectInput.DirectInput();
        /// foreach (SlimDX.DirectInput.DeviceInstance device in dinput.GetDevices(SlimDX.DirectInput.DeviceClass.GameController, SlimDX.DirectInput.DeviceEnumerationFlags.AttachedOnly))
        /// {
        ///     Console.WriteLine("Controller:" + device.InstanceName);
        ///
        ///     DirectX.Joystick.onLog = logMessages;
        ///     DirectX.Joystick.debug = false;
        ///     joystick = new DirectX.Joystick(dinput, device);
        ///
        ///     joystick.axisX.min = 1;
        ///     joystick.axisX.max = 99;
        ///     joystick.axisX.deadZone = 0;
        ///     joystick.axisX.saturation = 10000;
        ///
        ///     joystick.setJoystickValues();
        ///
        ///     controlHelper = new controllHelper(joystick);
        ///     joystick.start();
        ///
        ///     break;
        /// }
        /// </summary>
        /// <param name="dInput"></param>
        /// <param name="joystickInstance"></param>
        public Joystick(DirectInput dInput, DeviceInstance joystickInstance)
        {
            this.joystickInstance = joystickInstance;
            JoystickName          = joystickInstance.ProductName;

            joystickDevice = new SlimDX.DirectInput.Joystick(dInput, joystickInstance.InstanceGuid);  // slimDX replacement
            joystickDevice.SetNotification(onJoystickEvent);
            joystickDevice.Acquire();

            axisY     = new axis();
            axisX     = new axis();
            axisZ     = new axis();
            axisRy    = new axis();
            axisRx    = new axis();
            axisRz    = new axis();
            axisExtra = new axis();

            /* initiate default joystick values.*/
            setJoystickValues();
        }