コード例 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Plik tekstowy TXT (*.txt)|*.txt";
                if (sfd.ShowDialog(this) == DialogResult.OK)
                {
                    using (StreamWriter sw = new StreamWriter(sfd.FileName))
                    {
                        sw.WriteLine(string.Format("Raport wygenerowany: {0}", DateTime.Now.ToString()));
                        sw.WriteLine(string.Format("System operacyjny: {0}", Environment.OSVersion.ToString()));

                        foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly))
                        {
                            sw.WriteLine("------------------------------------------------------------------------");
                            sw.WriteLine(string.Format("ProductName: '{0}', InstanceName: '{1}', InstanceGuid: '{2}'", di.ProductName, di.InstanceName, di.InstanceGuid));
                            using (Device d = new Device(di.InstanceGuid))
                            {
                                sw.WriteLine();
                                sw.WriteLine("Możliwości:");
                                sw.WriteLine(string.Format("\tPrzycisków : {0}", d.Caps.NumberButtons));
                                sw.WriteLine(string.Format("\tHAT        : {0}", d.Caps.NumberPointOfViews));
                                sw.WriteLine(string.Format("\tOsi        : {0}", d.Caps.NumberAxes));

                                Microsoft.DirectX.DirectInput.DeviceObjectList list = d.GetObjects(Microsoft.DirectX.DirectInput.DeviceObjectTypeFlags.All);
                                sw.WriteLine();
                                sw.WriteLine(string.Format("Obiekty ({0}):", list.Count));
                                foreach (Microsoft.DirectX.DirectInput.DeviceObjectInstance o in list)
                                {
                                    sw.WriteLine(string.Format("\tNazwa: '{0}', Typ: {1} ({2})", o.Name, o.ObjectType, Utils.GetObjectTypeName(o.ObjectType)));
                                }
                            }
                        }
                    }
                    MessageBox.Show(this, "Pomyślnie utworzono raport.", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Wystąpił błąd podczas tworzenia raportu: " + ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void ShowSelected()
        {
            StopListening();

            if (!SaveCurrent())
            {
                _ingoreSelecting        = true;
                comboBox1.SelectedIndex = _lastIndex;
                _ingoreSelecting        = false;
                //return;
            }

            // wyczyszczenie
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            dataGridView1.Rows.Clear();
            dataGridView2.Rows.Clear();
            radioButton1.Checked = true;
            radioButton2.Checked = false;
            numericUpDown1.Value = 20;

            _lastIndex = comboBox1.SelectedIndex;

            Ctrl c = comboBox1.SelectedItem as Ctrl;

            if (c != null)
            {
                // poszukanie odpowiednika w konfiguracji
                _controller = FindController(c);

                textBox1.Text = _controller.Alias;
                textBox2.Text = _controller.Id.ToString();
                textBox3.Text = _controller.Index.ToString();
                if (_controller.UpdateType == UpdateStateType.ByChecking)
                {
                    radioButton2.Checked = true;
                }
                numericUpDown1.Value = _controller.ReadingStateInterval;

                // odczytanie systemowych informacji o kontrolerze
                if (_device != null)
                {
                    _device.Dispose();
                    _device = null;
                }
                if (c.Connected)
                {
                    _device        = new Device(c.ID);
                    _buttonsStates = new bool?[_device.Caps.NumberButtons];
                    _hatsStates    = new int[_device.Caps.NumberPointOfViews];
                    for (int i = 0; i < _hatsStates.Length; i++)
                    {
                        _hatsStates[i] = -2;
                    }
                    _axes = new int[8];
                }
                else
                {
                    _buttonsStates = new bool?[_controller.NumberOfObjects(InputType.Button)];
                    _hatsStates    = new int[_controller.NumberOfObjects(InputType.HATSwitch)];
                    for (int i = 0; i < _hatsStates.Length; i++)
                    {
                        _hatsStates[i] = -2;
                    }
                    _axes = new int[8];
                }

                textBox4.Text = c.Connected ? "podłączony" : "niepodłączony";

                // pokazanie konfiguracji przycisków

                // zwykłe przyciski
                for (int i = 0; i < _buttonsStates.Length; i++)
                {
                    int           index = 0;
                    InputVariable iv    = FindButton(_controller, i);
                    if (iv is IRepeatable)
                    {
                        index = dataGridView1.Rows.Add(string.Format("przycisk_{0}", i.ToString("000")), "False", iv.InternalID, iv.Description, iv.InputType, iv.Type, true, ((IRepeatable)iv).RepeatAfter, ((IRepeatable)iv).RepeatInterval);
                    }
                    else
                    {
                        index = dataGridView1.Rows.Add(string.Format("przycisk_{0}", i.ToString("000")), "False", iv.InternalID, iv.Description, iv.InputType, iv.Type, false, 250, 100);
                        dataGridView1.Rows[index].Cells[_powtarzajPo.Index].ReadOnly = true;
                        dataGridView1.Rows[index].Cells[_powtarzajCo.Index].ReadOnly = true;
                    }
                    dataGridView1.Rows[index].Tag = iv;
                }
                // przyciski HAT
                for (int i = 0; i < _hatsStates.Length; i++)
                {
                    int           index = 0;
                    InputVariable iv    = FindHAT(_controller, i);
                    if (iv is IRepeatable)
                    {
                        index = dataGridView1.Rows.Add(string.Format("hat_{0}", i.ToString("000")), "-1", iv.InternalID, iv.Description, iv.InputType, iv.Type, true, ((IRepeatable)iv).RepeatAfter, ((IRepeatable)iv).RepeatInterval);
                    }
                    else
                    {
                        index = dataGridView1.Rows.Add(string.Format("hat_{0}", i.ToString("000")), "-1", iv.InternalID, iv.Description, iv.InputType, iv.Type, false, 250, 100);
                        dataGridView1.Rows[index].Cells[_powtarzajPo.Index].ReadOnly = true;
                        dataGridView1.Rows[index].Cells[_powtarzajCo.Index].ReadOnly = true;
                    }
                    dataGridView1.Rows[index].Tag = iv;
                }

                dataGridView1.PerformLayout();

                // pokazanie konfiguracji osi
                if (_device != null)
                {
                    List <Guid> axes     = new List <Guid>();
                    int         extCount = 0;
                    Microsoft.DirectX.DirectInput.DeviceObjectList list = _device.GetObjects(Microsoft.DirectX.DirectInput.DeviceObjectTypeFlags.Axis);
                    foreach (Microsoft.DirectX.DirectInput.DeviceObjectInstance o in list)
                    {
                        if (AxisTypeUtils.IsProperGuidForAxis(o.ObjectType))
                        {
                            if (axes.Contains(o.ObjectType))
                            {
                                continue;
                            }
                            _device.Properties.SetRange(Microsoft.DirectX.DirectInput.ParameterHow.ById, o.ObjectId, new Microsoft.DirectX.DirectInput.InputRange(0, iAXIS_MAX));
                            InputVariable iv    = FindAxis(_controller, o.ObjectType, o.Name, extCount);
                            int           index = dataGridView2.Rows.Add(o.Name, iv.InternalID, iv.Description, ((IAxis)iv).Reverse, ((IAxis)iv).Min, ((IAxis)iv).Max, 0);
                            dataGridView2.Rows[index].Tag = iv;
                            if (o.ObjectType == Microsoft.DirectX.DirectInput.ObjectTypeGuid.Slider)
                            {
                                extCount++;
                            }
                        }
                    }
                }
                else
                {
                    // kontroler nie jest podłączony
                    for (int i = 0; i < _controller.Variables.Length; i++)
                    {
                        if (_controller.Variables[i].InputType == InputType.Axis)
                        {
                            InputVariable iv    = _controller.Variables[i];
                            int           index = dataGridView2.Rows.Add(((IAxis)iv).AxisName, iv.InternalID, iv.Description, ((IAxis)iv).Reverse, ((IAxis)iv).Min, ((IAxis)iv).Max, 0);
                            dataGridView2.Rows[index].Tag = iv;
                        }
                    }
                }

                dataGridView2.PerformLayout();

                StartListening();
            }
        }