public AddEditKeysDialog(ModulesConfiguration configuration, KeysInputVariable keys) { InitializeComponent(); Array vals = Enum.GetValues(typeof(Microsoft.DirectX.DirectInput.Key)); List <Microsoft.DirectX.DirectInput.Key> tmp = new List <Microsoft.DirectX.DirectInput.Key>(); for (int i = 0; i < vals.Length; i++) { if (tmp.Contains((Microsoft.DirectX.DirectInput.Key)vals.GetValue(i))) { continue; } tmp.Add((Microsoft.DirectX.DirectInput.Key)vals.GetValue(i)); checkedListBox1.Items.Add(new KV() { Key = (Microsoft.DirectX.DirectInput.Key)vals.GetValue(i), Name = Utils.KeyToFriendlyName((Microsoft.DirectX.DirectInput.Key)vals.GetValue(i)) }); } checkedListBox1.Sorted = true; _configuration = configuration; _keys = keys; if (_keys != null) { Text = "Edycja klawiszy '" + _keys.ID + "'"; textBox1.Text = _keys.ID; textBox2.Text = _keys.Description; checkBox1.Checked = _keys.Repeat; numericUpDown1.Value = _keys.RepeatAfter; numericUpDown2.Value = _keys.RepeatInterval; for (int i = 0; i < _keys.Keys.Length; i++) { for (int j = 0; j < checkedListBox1.Items.Count; j++) { if (((KV)checkedListBox1.Items[j]).Key == _keys.Keys[i]) { checkedListBox1.SetItemChecked(j, true); break; } } } } else { Text = "Dodaj klawisze"; } textBox1.Focus(); _defaultColor = textBox3.BackColor; _defaultColorText = textBox3.ForeColor; _keyboard = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard); _keyboard.SetDataFormat(Microsoft.DirectX.DirectInput.DeviceDataFormat.Keyboard); _keyboard.SetCooperativeLevel(IntPtr.Zero, Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive); _keyboard.Acquire(); }
private void button1_Click(object sender, EventArgs e) { // sprawdzenie czy id jest unikalne string id = textBox1.Text.Trim(); if (id.Length == 0) { MessageBox.Show(this, "Nie podano identyfikatora.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.Focus(); return; } for (int i = 0; i < _configuration.Keys.Length; i++) { if (_configuration.Keys[i] == _keys) { continue; } if (_configuration.Keys[i].ID == id) { MessageBox.Show(this, "Wprowadzony identyfikator jest już zajęty.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.Focus(); return; } } // sprawdzenie czy są jakieś klawisze if (_k.Count == 0) { MessageBox.Show(this, "Nie wprowadzono żadnych klawiszy do śledzenia.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox3.Focus(); return; } KeysInputVariable k = _keys; if (k == null) { k = new KeysInputVariable(); } k.ID = id; k.Description = textBox2.Text; k.Repeat = checkBox1.Checked; k.RepeatAfter = (int)numericUpDown1.Value; k.RepeatInterval = (int)numericUpDown2.Value; k.Keys = _k.ToArray(); if (_keys == null) { _keys = k; } DialogResult = DialogResult.OK; Close(); }
private void button4_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { KeysInputVariable k = listView1.SelectedItems[0].Tag as KeysInputVariable; if (k != null) { AddEditKeysDialog d = new AddEditKeysDialog(Configuration, k); if (d.ShowDialog(this) == DialogResult.OK) { ShowKeys(); } } } }
private void button5_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { KeysInputVariable k = listView1.SelectedItems[0].Tag as KeysInputVariable; if (k != null) { if (MessageBox.Show(this, "Czy napewno chcesz usunąć kombinację klawiszy '" + k.ID + "' ?", "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { List <KeysInputVariable> keys = new List <KeysInputVariable>(Configuration.Keys); keys.Remove(k); Configuration.Keys = keys.ToArray(); ShowKeys(); } } } }
private void ShowKeys() { listView1.Items.Clear(); if (Configuration.Keys != null) { Array.Sort(Configuration.Keys); for (int i = 0; i < Configuration.Keys.Length; i++) { KeysInputVariable k = Configuration.Keys[i]; ListViewItem item = new ListViewItem(k.ID); item.SubItems.Add(k.Description); item.SubItems.Add(k.KeysText); item.SubItems.Add(k.Repeat ? "tak" : "nie"); item.SubItems.Add(k.RepeatAfter.ToString()); item.SubItems.Add(k.RepeatInterval.ToString()); item.Tag = k; listView1.Items.Add(item); } } listView1.SelectedItems.Clear(); listView1_SelectedIndexChanged(this, EventArgs.Empty); }
public static ModulesConfiguration Load(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException(fileName); } ModulesConfiguration c = new ModulesConfiguration(); XmlDocument xml = new XmlDocument(); xml.Load(fileName); XmlNodeList nodes = xml.SelectNodes("configuration/input/keys"); if (nodes != null && nodes.Count > 0) { List <KeysInputVariable> keys = new List <KeysInputVariable>(); foreach (XmlNode node in nodes) { keys.Add(KeysInputVariable.Read(node)); } c.Keys = keys.ToArray(); } return(c); }
private ModulesConfiguration() { Keys = new KeysInputVariable[0]; }