Пример #1
0
        private void UpdateDeviceList()
        {
            if (!this.listView.IsEnabled)
            {
                return;
            }

            var devices = new List <IIinputDevice>();

            devices.Add(VirtualKeyboard.Instance);
            devices.AddRange(DeviceScanner.GetHidKeyboards());
            devices.AddRange(DeviceScanner.GetHidMice());
            devices.AddRange(DeviceScanner.GetUsbGamepads());
            devices.AddRange(DeviceScanner.GetOtherHidDevices());
            var devicesToRemove = new List <IIinputDevice>();

            foreach (var device in devices)
            {
                if (device.DeviceType != DeviceType.Other)
                {
                    continue;
                }

                ushort vid        = Convert.ToUInt16(device.Vendor, 16);
                ushort pid        = Convert.ToUInt16(device.Product, 16);
                var    rawDevices = HidDataReader.GetDevices().Where(d => d.ProductId == pid && d.VendorId == vid);

                if (rawDevices.Count() == 0)
                {
                    devicesToRemove.Add(device);
                }
            }

            foreach (var deviceToRemove in devicesToRemove)
            {
                devices.Remove(deviceToRemove);
            }

            this.listView.ItemsSource   = devices;
            this.listView.SelectedIndex = -1;
            var view             = (CollectionView)CollectionViewSource.GetDefaultView(this.listView.ItemsSource);
            var groupDescription = new PropertyGroupDescription("DeviceType");

            view.GroupDescriptions.Add(groupDescription);

            this.lastData = new byte[0];
        }
Пример #2
0
        private void UpdateDeviceList()
        {
            if (!this.listView.IsEnabled)
            {
                return;
            }

            var devices = HidDataReader.GetDevices();

            foreach (var d in devices)
            {
                ushort vid = d.VendorId;
                ushort pid = d.ProductId;
            }

            this.listView.ItemsSource   = devices;
            this.listView.SelectedIndex = -1;
            var view             = (CollectionView)CollectionViewSource.GetDefaultView(this.listView.ItemsSource);
            var groupDescription = new PropertyGroupDescription("DeviceType");

            view.GroupDescriptions.Add(groupDescription);

            this.lastData = new byte[0];
        }