示例#1
0
 /// <summary>
 /// Shutdown device access
 /// </summary>
 public override void FinishDX()
 {
     if (null != m_device)
     {
         log.DebugFormat("Release DirectInput device: {0}", m_device.Information.ProductName);
         m_device.Unacquire( );
         m_device = null;
     }
 }
 public void Dispose()
 {
     if (stick != null)
     {
         stick.Unacquire();
         stick.Dispose();
         stick = null;
     }
 }
示例#3
0
        public override bool Exit()
        {
            if (joystick != null)
            {
                joystick.Unacquire();
            }

            return(true);
        }
示例#4
0
        public void StopEventHandling()
        {
            m_abort = true;
            if ((m_thread != null) && m_thread.IsAlive)
            {
                m_thread.Abort( );
            }
            if (m_device != null)
            {
                if (m_device.IsDisposed)
                {
                    return;
                }

                m_device.Unacquire( );
                m_device.SetNotification(null);
            }
        }
示例#5
0
        public bool AcquireJoystick(Guid guid)
        {
            try
            {
                if (_joystick != null)
                {
                    _joystick.Unacquire();
                    _joystick = null;
                }

                var dinput = new DirectInput();
                foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly))
                {
                    if (device.InstanceGuid == guid)
                    {
                        _joystick = new SharpDX.DirectInput.Joystick(dinput, device.InstanceGuid);
                    }
                }

                if (_joystick != null)
                {
                    foreach (DeviceObjectInstance deviceObject in _joystick.GetObjects())
                    {
                        //if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                        switch (deviceObject.ObjectId.Flags)
                        {
                        case DeviceObjectTypeFlags.Axis:
                        case DeviceObjectTypeFlags.AbsoluteAxis:
                        case DeviceObjectTypeFlags.RelativeAxis:
                            var ir = _joystick.GetObjectPropertiesById(deviceObject.ObjectId);
                            if (ir != null)
                            {
                                try
                                {
                                    ir.Range = new InputRange(-100, 100);
                                }
                                catch (Exception ex)
                                {
                                    MainForm.LogExceptionToFile(ex);
                                }
                            }
                            break;
                        }
                    }

                    _joystick.Acquire();

                    var cps = _joystick.Capabilities;
                    AxisCount = cps.AxeCount;

                    UpdateStatus();
                }
            }
            catch (Exception ex)
            {
                MainForm.LogExceptionToFile(ex);
                return(false);
            }

            return(true);
        }
示例#6
0
 public void ReleaseJoystick() => _joystick?.Unacquire();