Ejemplo n.º 1
0
        public override void Stop()
        {
            lock (_sync)
            {
                if (_acquired)
                {
                    _timer.Change(Timeout.Infinite, Period);
                    _joystick.Unacquire();

                    _acquired = false;
                }
            }
        }
Ejemplo n.º 2
0
        private void TJsListening()
        {
            MessageBox.Show("监听到手柄");
            m_JoystickInfoLast = new JoystickInfoClass();
            m_JoystickInfoNew  = new JoystickInfoClass();
            for (int i = 0; i < m_JoystickInfoNew.Buttons.Length; i++)
            {
                m_JoystickInfoLast.Buttons[i] = false;//初始化时,所有按键均未按下
            }
            m_JoystickInfoLast.PointOfViewControllers[0] = JoystickPViewHatInfo.PViewHat_Null;
            try
            {
                while (true)
                {
                    //初始化新按键
                    for (int i = 0; i < m_JoystickInfoNew.Buttons.Length; i++)
                    {
                        m_JoystickInfoNew.Buttons[i] = false;//初始化时,所有按键均未按下
                    }
                    m_JoystickInfoNew.PointOfViewControllers[0] = JoystickPViewHatInfo.PViewHat_Null;

                    //如果手柄掉了,会引发异常,结束该线程
                    var CurJoyState = curJoystick.GetCurrentState();

                    //获取按键信息
                    //获取的按键名比厂家软件显示的小1
                    int ButtonsLen = CurJoyState.Buttons.Length;
                    for (int j = 0; j < ButtonsLen; j++)
                    {
                        if (Convert.ToInt32(CurJoyState.Buttons[j]) > 0)
                        {
                            m_JoystickInfoNew.Buttons[j] = true;//按下
                        }
                    }

                    //获取Point Of View Hat信息
                    //int PointOfViewLen= b.GetPointOfView().Length;
                    int PointOfViewLen = CurJoyState.PointOfViewControllers.Length;
                    for (int j = 0; j < PointOfViewLen; j++)
                    {
                        //数据范围是0,4500,9000,13500,18000,22500,27000,31500
                        //没有按的时候是-1
                        m_JoystickInfoNew.PointOfViewControllers[j] = (JoystickPViewHatInfo)Convert.ToInt32(CurJoyState.PointOfViewControllers[j]);
                    }

                    //获取Slider信息
                    int SliderLen = CurJoyState.Sliders.Length;
                    for (int j = 0; j < SliderLen; j++)
                    {
                        m_JoystickInfoNew.AccelerationSliders[j] = CurJoyState.AccelerationSliders[j];
                        m_JoystickInfoNew.ForceSliders[j]        = CurJoyState.ForceSliders[j];
                        m_JoystickInfoNew.VelocitySliders[j]     = CurJoyState.VelocitySliders[j];
                        m_JoystickInfoNew.Sliders[j]             = CurJoyState.Sliders[j];
                    }

                    //获取摇杆信息
                    m_JoystickInfoNew.X                    = CurJoyState.X;
                    m_JoystickInfoNew.Y                    = CurJoyState.Y;
                    m_JoystickInfoNew.Z                    = CurJoyState.Z;
                    m_JoystickInfoNew.VelocityX            = CurJoyState.VelocityX;
                    m_JoystickInfoNew.VelocityY            = CurJoyState.VelocityY;
                    m_JoystickInfoNew.VelocityZ            = CurJoyState.VelocityZ;
                    m_JoystickInfoNew.TorqueX              = CurJoyState.TorqueX;
                    m_JoystickInfoNew.TorqueY              = CurJoyState.TorqueY;
                    m_JoystickInfoNew.TorqueZ              = CurJoyState.TorqueZ;
                    m_JoystickInfoNew.RotationX            = CurJoyState.RotationX;
                    m_JoystickInfoNew.RotationY            = CurJoyState.RotationY;
                    m_JoystickInfoNew.RotationZ            = CurJoyState.RotationZ;
                    m_JoystickInfoNew.ForceX               = CurJoyState.ForceX;
                    m_JoystickInfoNew.ForceY               = CurJoyState.ForceY;
                    m_JoystickInfoNew.ForceZ               = CurJoyState.ForceZ;
                    m_JoystickInfoNew.AngularVelocityX     = CurJoyState.AngularVelocityX;
                    m_JoystickInfoNew.AngularVelocityY     = CurJoyState.AngularVelocityY;
                    m_JoystickInfoNew.AngularVelocityZ     = CurJoyState.AngularVelocityZ;
                    m_JoystickInfoNew.AngularAccelerationX = CurJoyState.AngularAccelerationX;
                    m_JoystickInfoNew.AngularAccelerationY = CurJoyState.AngularAccelerationY;
                    m_JoystickInfoNew.AngularAccelerationZ = CurJoyState.AngularAccelerationZ;
                    m_JoystickInfoNew.AccelerationX        = CurJoyState.AccelerationX;
                    m_JoystickInfoNew.AccelerationY        = CurJoyState.AccelerationY;
                    m_JoystickInfoNew.AccelerationZ        = CurJoyState.AccelerationZ;
                    bool bIsSameJs = CompareJoystickInfoClass(m_JoystickInfoLast, m_JoystickInfoNew);
                }
            }
            catch (Exception ex)
            {
                curJoystick.Unacquire();
                JoystickName = "";
            }
        }