public void LoadConfig(string configFile) { ConfigFile = configFile; Items.Clear(); using (KeyManagerDataSet DConfig = new KeyManagerDataSet()) { DConfig.ReadXml(configFile); if (DConfig.KeyManager.Count == 0) { throw new FormatException("Invalid configuration file: " + configFile); } KeyManagerDataSet.KeyManagerRow ptrDev = DConfig.KeyManager[0]; ActivationSequence = ptrDev.ActivationSequence; SequenceTimeout = ptrDev.SequenceTimeout; ActivationType = (KeyManagerActivationSequenceType)Enum.Parse(typeof(KeyManagerActivationSequenceType), ptrDev.ActivationType); Modifier = (Keys)ptrDev.ComboKeyModifiers; ActivationKey = (Keys)ptrDev.ComboKey; foreach (KeyManagerDataSet.KeyManagerItemRow ptrItem in ptrDev.GetKeyManagerItemRows()) { KeyManagerItem tItem = new KeyManagerItem(); tItem.Name = ptrItem.Name; tItem.Application = ptrItem.Application; tItem.Argument = ptrItem.Arguments; tItem.ActionType = (KeyManagerActionType)Enum.Parse(typeof(KeyManagerActionType), ptrItem.ActionType); tItem.HotKey = ptrItem.HotKey; Items.Add(tItem); } } }
private void tButton_Click(object sender, EventArgs e) { Trace.WriteLine(((Button)sender).Text + " clicked."); KeyManagerItem ptrItem = KbManager.Items.Find(item => item.BindedControl == sender); ProcessAction(ptrItem); }
private void PopulateItems() { ActionItems = new List <KeyManagerItem>(); foreach (DataGridViewRow ptrRow in tbItems.Rows) { KeyManagerItem tItem = new KeyManagerItem(); string tHotKey = GetCellValue(ptrRow.Cells[0]); tItem.HotKey = string.IsNullOrEmpty(tHotKey) ? (char)0x00 : tHotKey[0]; tItem.Name = GetCellValue(ptrRow.Cells[1]); tItem.ActionType = (KeyManagerActionType)Enum.Parse(typeof(KeyManagerActionType), ptrRow.Cells[2].Value.ToString()); tItem.Application = GetCellValue(ptrRow.Cells[3]); tItem.Argument = GetCellValue(ptrRow.Cells[4]); ActionItems.Add(tItem); } }
private void ProcessAction(KeyManagerItem item) { switch (item.ActionType) { case KeyManagerActionType.StartProgram: Process.Start(item.Application, item.Argument); break; case KeyManagerActionType.ShutDown: //Process.Start("shutdown", "/s /t 10"); break; case KeyManagerActionType.Restart: //Process.Start("shutdown", "/r /t 10"); break; } StartMonitor(); }
private void Settings_Load(object sender, EventArgs e) { cbActivationMode.SelectedIndex = (int)keyManager.ActivationType; txtActivationSequence.Text = keyManager.ActivationSequence; txtTimeout.Text = keyManager.SequenceTimeout.ToString(); hotKeyCtrl.HotkeyModifiers = keyManager.Modifier; hotKeyCtrl.Hotkey = keyManager.ActivationKey; tbItems.Rows.Clear(); tbItems.Rows.Add(keyManager.Items.Count); for (int x = 0; x < keyManager.Items.Count; x++) { KeyManagerItem ptrItem = keyManager.Items[x]; DataGridViewRow ptrRow = tbItems.Rows[x]; ptrRow.Cells[0].Value = ptrItem.HotKey; ptrRow.Cells[1].Value = ptrItem.Name; ptrRow.Cells[2].Value = ptrItem.ActionType.ToString(); ptrRow.Cells[3].Value = ptrItem.Application; ptrRow.Cells[4].Value = ptrItem.Argument; } }
private bool ValidateConfiguration() { for (int x = 0; x < ActionItems.Count; x++) { KeyManagerItem ptrItem = ActionItems[x]; if (string.IsNullOrEmpty(ptrItem.Name)) { MessageBox.Show("Row " + x.ToString() + ": Name cannot be empty!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (ptrItem.ActionType == KeyManagerActionType.StartProgram) { if (string.IsNullOrEmpty(ptrItem.Application)) { MessageBox.Show("Row " + x.ToString() + ": Target application not defined!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } return(true); }