private void lviControls_Leave(object sender, System.EventArgs e)
        {
            if(inputSelectedListViewItem != null)
            {
                inputDevice.Dispose();
                inputDevice = null;

                inputSelectedListViewItem.BackColor = Color.White;
                inputSelectedListViewItem = null;
                inputDeviceConfigTimer.Stop();
            }
        }
        private void DisplayControls()
        {
            if((Settings.Current.Players == null) ||
                (Settings.Current.Players.Length <= inputSelectedPlayerIndex) ||
                (cmbController.SelectedIndex < 0))
            {
                return;
            }
            Controls controls = Settings.Current.Players[inputSelectedPlayerIndex].Controls;
            Microsoft.DirectX.DirectInput.DeviceInstance controller = inputAvailableDevices[cmbController.SelectedIndex];
            DirectInput.Device device = new DirectInput.Device(controller.Instance);

            //            int pop = device.Properties.GetDeadZone(DirectInput.ParameterHow.ById, 0);
            //            pop = device.Properties.GetDeadZone(DirectInput.ParameterHow.ById, 1);
            //            pop = device.Properties.GetDeadZone(DirectInput.ParameterHow.ById, 2);
            //            pop = device.Properties.GetDeadZone(DirectInput.ParameterHow.ById, 3);
            bool analog = device.Capabilities.NumberAxes > 0;

            lviControls.Items.Clear();
            foreach(FieldInfo field in controls.GetType().GetFields())
            {
                bool analogField = field.GetCustomAttributes(typeof(AnalogControlAttribute), true).Length > 0;
                if(analog || !analogField)
                {
                    ListViewItem item = new ListViewItem(new string[] {field.Name, (string)field.GetValue(controls)});
                    item.Tag = field;
                    lviControls.Items.Add(item);
                }
            }
            device.Dispose();
        }
        private void lviControls_DoubleClick(object sender, System.EventArgs e)
        {
            if((lviControls.SelectedItems.Count > 0) &&
                (lviControls.Focused))
            {
                if(inputSelectedListViewItem != null)
                {
                    lviControls_Leave(sender, e);
                }
                inputPreviousSelectedControl = null;
                Microsoft.DirectX.DirectInput.DeviceInstance controller = inputAvailableDevices[cmbController.SelectedIndex];
                inputDevice = new DirectInput.Device(controller.Instance);
                if(inputDevice.Capabilities.DeviceType == DirectInput.DeviceType.Joystick)
                {
                    inputDevice.SetDataFormat(DirectInput.DeviceDataFormat.Joystick);
                    foreach (DirectInput.ObjectInstance d in inputDevice.Objects)
                    {
                        // For axes that are returned, set the DIPROP_RANGE property for the
                        // enumerated axis in order to scale min/max values.

                        if ((0 != (d.Type & (int)DirectInput.ObjectTypeFlags.Axis)))
                        {
                            // Set the range for the axis.
                            inputDevice.Properties.SetRange(DirectInput.ParameterHow.ById, d.Type, new DirectInput.InputRange(-1000, +1000));
                        }
                    }
                }
                else
                {
                    inputDevice.SetDataFormat(DirectInput.DeviceDataFormat.Keyboard);
                }
                inputDevice.SetCooperativeLevel(this.Handle, DirectInput.CooperativeLevelFlags.Foreground | DirectInput.CooperativeLevelFlags.NonExclusive);

                inputSelectedListViewItem = lviControls.SelectedItems[0];
                lviControls.SelectedItems.Clear();
                inputSelectedListViewItem.BackColor = Color.Red;
                inputDeviceConfigTimer.Start();
            }
        }