当前位置: 首页>>代码示例>>C#>>正文


C# Device.GetGuid方法代码示例

本文整理汇总了C#中Device.GetGuid方法的典型用法代码示例。如果您正苦于以下问题:C# Device.GetGuid方法的具体用法?C# Device.GetGuid怎么用?C# Device.GetGuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device.GetGuid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QueryDeviceCaps

        bool QueryDeviceCaps(Device stick)
        {
            Debug.Print("[{0}] Querying joystick {1}",
                TypeName, stick.GetGuid());

            try
            {
                Debug.Indent();
                HidProtocolCaps caps;

                if (GetPreparsedData(stick.Handle, ref PreparsedData) &&
                    GetDeviceCaps(stick, PreparsedData, out caps))
                {
                    if (stick.AxisCaps.Count >= JoystickState.MaxAxes ||
                        stick.ButtonCaps.Count >= JoystickState.MaxButtons)
                    {
                        Debug.Print("Device {0} has {1} and {2} buttons. This might be a touch device - skipping.",
                            stick.Handle, stick.AxisCaps.Count, stick.ButtonCaps.Count);
                        return false;
                    }

                    for (int i = 0; i < stick.AxisCaps.Count; i++)
                    {
                        Debug.Print("Analyzing value collection {0} {1} {2}",
                            i,
                            stick.AxisCaps[i].IsRange ? "range" : "",
                            stick.AxisCaps[i].IsAlias ? "alias" : "");

                        if (stick.AxisCaps[i].IsRange || stick.AxisCaps[i].IsAlias)
                        {
                            Debug.Print("Skipping value collection {0}", i);
                            continue;
                        }

                        HIDPage page = stick.AxisCaps[i].UsagePage;
                        short collection = stick.AxisCaps[i].LinkCollection;
                        switch (page)
                        {
                            case HIDPage.GenericDesktop:
                                HIDUsageGD gd_usage = (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage;
                                switch (gd_usage)
                                {
                                    case HIDUsageGD.X:
                                    case HIDUsageGD.Y:
                                    case HIDUsageGD.Z:
                                    case HIDUsageGD.Rx:
                                    case HIDUsageGD.Ry:
                                    case HIDUsageGD.Rz:
                                    case HIDUsageGD.Slider:
                                    case HIDUsageGD.Dial:
                                    case HIDUsageGD.Wheel:
                                        Debug.Print("Found axis {0} ({1} / {2})",
                                            JoystickAxis.Axis0 + stick.GetCapabilities().AxisCount,
                                            page, (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage);
                                        stick.SetAxis(collection, page, stick.AxisCaps[i].NotRange.Usage, 0);
                                        break;

                                    case HIDUsageGD.Hatswitch:
                                        Debug.Print("Found hat {0} ({1} / {2})",
                                            JoystickHat.Hat0 + stick.GetCapabilities().HatCount,
                                            page, (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage);
                                        stick.SetHat(collection, page, stick.AxisCaps[i].NotRange.Usage, HatPosition.Centered);
                                        break;

                                    default:
                                        Debug.Print("Unknown usage {0} for page {1}",
                                            gd_usage, page);
                                        break;
                                }
                                break;

                            case HIDPage.Simulation:
                                switch ((HIDUsageSim)stick.AxisCaps[i].NotRange.Usage)
                                {
                                    case HIDUsageSim.Rudder:
                                    case HIDUsageSim.Throttle:
                                        Debug.Print("Found simulation axis {0} ({1} / {2})",
                                            JoystickAxis.Axis0 + stick.GetCapabilities().AxisCount,
                                            page, (HIDUsageSim)stick.AxisCaps[i].NotRange.Usage);
                                        stick.SetAxis(collection, page, stick.AxisCaps[i].NotRange.Usage, 0);
                                        break;
                                }
                                break;

                            default:
                                Debug.Print("Unknown page {0}", page);
                                break;
                        }
                    }

                    for (int i = 0; i < stick.ButtonCaps.Count; i++)
                    {
                        Debug.Print("Analyzing button collection {0} {1} {2}",
                            i,
                            stick.ButtonCaps[i].IsRange ? "range" : "",
                            stick.ButtonCaps[i].IsAlias ? "alias" : "");

                        if (stick.ButtonCaps[i].IsAlias)
                        {
                            Debug.Print("Skipping button collection {0}", i);
//.........这里部分代码省略.........
开发者ID:RockyTV,项目名称:opentk,代码行数:101,代码来源:WinRawJoystick.cs

示例2: RefreshDevices

        public void RefreshDevices()
        {
            // Mark all devices as disconnected. We will check which of those
            // are connected below.
            foreach (var device in Devices)
            {
                device.SetConnected(false);
            }

            // Discover joystick devices
            int xinput_device_count = 0;
            foreach (RawInputDeviceList dev in WinRawInput.GetDeviceList())
            {
                // Skip non-joystick devices
                if (dev.Type != RawInputDeviceType.HID)
                    continue;

                // We use the device handle as the hardware id.
                // This works, but the handle will change whenever the
                // device is unplugged/replugged. We compensate for this
                // by checking device GUIDs, below.
                // Note: we cannot use the GUID as the hardware id,
                // because it is costly to query (and we need to query
                // that every time we process a device event.)
                IntPtr handle = dev.Device;
                bool is_xinput = IsXInput(handle);
                Guid guid = GetDeviceGuid(handle);
                long hardware_id = handle.ToInt64();

                Device device = Devices.FromHardwareId(hardware_id);
                if (device != null)
                {
                    // We have already opened this device, mark it as connected
                    device.SetConnected(true);
                }
                else
                {
                    device = new Device(handle, guid, is_xinput,
                        is_xinput ? xinput_device_count++ : 0);

                    // This is a new device, query its capabilities and add it
                    // to the device list
                    if (!QueryDeviceCaps(device))
                    {
                        continue;
                    }
                    device.SetConnected(true);

                    // Check if a disconnected device with identical GUID already exists.
                    // If so, replace that device with this instance.
                    Device match = null;
                    foreach (Device candidate in Devices)
                    {
                        if (candidate.GetGuid() == guid && !candidate.GetCapabilities().IsConnected)
                        {
                            match = candidate;
                        }
                    }
                    if (match != null)
                    {
                        Devices.Remove(match.Handle.ToInt64());
                    }

                    Devices.Add(hardware_id, device);

                    Debug.Print("[{0}] Connected joystick {1} ({2})",
                        GetType().Name, device.GetGuid(), device.GetCapabilities());
                }
            }
        }
开发者ID:RockyTV,项目名称:opentk,代码行数:70,代码来源:WinRawJoystick.cs


注:本文中的Device.GetGuid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。