示例#1
0
 /// <summary>
 /// Start event handling
 /// </summary>
 public void StartEventHandling()
 {
     if ((m_thread != null) && m_thread.IsAlive)
     {
         return;                         // running ..
     }
     m_prevState = new JoystickState( ); // reset before starting
     m_device.SetNotification(m_joystickNotification);
     m_device.Acquire( );
     m_abort = false;
     // start Thread
     m_thread = new Thread(new ThreadStart(TaskLoop));
     m_thread.Start( );
 }
        public InputDeviceJoystickWindows(DirectInput di, DeviceInstance d, bool paxison)
        {
            jsi = new InputDeviceIdentity()
            {
                Instanceguid = d.InstanceGuid, Productguid = d.ProductGuid, Name = d.InstanceName.RemoveTrailingCZeros()
            };

            axisevents = paxison;

            stick = new SharpDX.DirectInput.Joystick(di, d.InstanceGuid);
            stick.SetNotification(eventhandle);
            stick.Acquire();

            axispresent = new bool[AxisCount];
            axisvalue   = Enumerable.Repeat(AxisNullValue, AxisCount).ToArray();

            Capabilities c = stick.Capabilities;

            butstate = new bool[c.ButtonCount];

            povvalue    = Enumerable.Repeat(POVNotPressed, c.PovCount).ToArray();
            slidercount = 0;

            DeviceProperties p = stick.Properties;

            jsi.VendorId  = p.VendorId;
            jsi.ProductId = p.ProductId;

            //   string s = p.PortDisplayName;

            System.Diagnostics.Debug.WriteLine("JOY {0} {1} but {2} pov {3}", jsi.Name, jsi.Productguid, butstate.Length, povvalue.Length);

            foreach (DeviceObjectInstance deviceObject in stick.GetObjects())
            {
                if ((deviceObject.ObjectId.Flags & DeviceObjectTypeFlags.Axis) != 0)
                {
                    System.Guid guid = deviceObject.ObjectType;
                    //System.Diagnostics.Debug.WriteLine("  {0} {1} {2} {3} {4}", jsi.Name, deviceObject.UsagePage, deviceObject.Usage, deviceObject.Offset, guid.ToString());

                    if (guid == ObjectGuid.XAxis)
                    {
                        axispresent[(int)Axis.X] = true;
                    }
                    else if (guid == ObjectGuid.YAxis)
                    {
                        axispresent[(int)Axis.Y] = true;
                    }
                    else if (guid == ObjectGuid.ZAxis)
                    {
                        axispresent[(int)Axis.Z] = true;
                    }
                    else if (guid == ObjectGuid.RxAxis)
                    {
                        axispresent[(int)Axis.RX] = true;
                    }
                    else if (guid == ObjectGuid.RyAxis)
                    {
                        axispresent[(int)Axis.RY] = true;
                    }
                    else if (guid == ObjectGuid.RzAxis)
                    {
                        axispresent[(int)Axis.RZ] = true;
                    }
                    else if (guid == ObjectGuid.Slider)
                    {
                        int axisentry = (int)Axis.U + slidercount;
                        if (axisentry < AxisCount)
                        {
                            axispresent[axisentry] = true;
                            slidercount++;      // must be sliders, only ones left with axis
                            //System.Diagnostics.Debug.WriteLine("Slider " + slidercount);
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Unknown Axis " + guid.ToString());
                    }

                    ObjectProperties o = stick.GetObjectPropertiesById(deviceObject.ObjectId);
                    o.Range = new InputRange(AxisMinRange, AxisMaxRange);
                }
            }
        }