コード例 #1
0
        public InputDeviceKeyboard(DirectInput di, DeviceInstance d)
        {
            // those silly foreign people call keyboard something other than it in english, so we need to fix it to english

            ksi = new InputDeviceIdentity()
            {
                Instanceguid = d.InstanceGuid, Productguid = d.ProductGuid, Name = "Keyboard"
            };

            keyboard = new Keyboard(di);
            keyboard.Properties.BufferSize = 128;
            keyboard.SetNotification(eventhandle);
            keyboard.Acquire();
        }
コード例 #2
0
        public InputDeviceMouse(DirectInput di, DeviceInstance d)
        {
            // those silly foreign people call mouse something other than it in english, so we need to fix it to english

            msi = new InputDeviceIdentity()
            {
                Instanceguid = d.InstanceGuid, Productguid = d.ProductGuid, Name = "Mouse"
            };

            mouse = new SharpDX.DirectInput.Mouse(di);
            mouse.SetNotification(eventhandle);
            mouse.Acquire();
            Capabilities c = mouse.Capabilities;

            butstate = new bool[c.ButtonCount];
        }
コード例 #3
0
        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);
                }
            }
        }