private void InitializeShortcutKeys() { foreach (var shortcutKey in Program.SysConfig.LocalHotKeyContainer) { if (shortcutKey != null) { switch (shortcutKey.Name) { case "takePicture": this.txtTakePicture.Text = HotKeyShared.CombineShortcut(shortcutKey.Modifier, shortcutKey.Key); break; case "zoomIn": this.txtZoomIn.Text = HotKeyShared.CombineShortcut(shortcutKey.Modifier, shortcutKey.Key); break; case "zoomOut": this.txtZoomOut.Text = HotKeyShared.CombineShortcut(shortcutKey.Modifier, shortcutKey.Key); break; case "startRecord": this.txtStart.Text = HotKeyShared.CombineShortcut(shortcutKey.Modifier, shortcutKey.Key); break; case "fireLaser": this.txtFire.Text = HotKeyShared.CombineShortcut(shortcutKey.Modifier, shortcutKey.Key); break; } } } }
GlobalHotKey CreateHotKey(string name, string shortcut, object tag) { object[] Parsed = HotKeyShared.ParseShortcut(shortcut); Modifiers mod = (Modifiers)Parsed.GetValue(0); Keys key = (Keys)Parsed.GetValue(1); GlobalHotKey toReturn = new GlobalHotKey(name, mod, key); toReturn.Tag = tag; return(toReturn); }
private void btnRegister_Click(object sender, EventArgs e) { if (hotKeyControl1.Text != Keys.None.ToString()) { if (!string.IsNullOrEmpty(txtProgram.Text) && HotKeyShared.IsValidHotkeyName(txtName.Text)) { LocalHotKey NewLocalHotKey = new LocalHotKey(txtName.Text, hotKeyControl1.UserModifier, hotKeyControl1.UserKey); NewLocalHotKey.Tag = txtProgram.Text; MainForm.MyHotKeyManager.AddLocalHotKey(NewLocalHotKey); this.Close(); } } }
private void btnOk_Click(object sender, EventArgs e) { try { if (txtButton.Text != Keys.None.ToString() && !txtButton.Text.Trim().EndsWith("+")) { if (!string.IsNullOrEmpty(txtProgram.Text) && HotKeyShared.IsValidHotkeyName(txtName.Text)) { MainForm.MyHotKeyManager.AddGlobalHotKey(CreateHotKey(txtName.Text, txtButton.Text, txtProgram.Text)); } } this.Close(); } catch (HotKeyAlreadyRegisteredException) { MessageBox.Show("A hotkey with the same name or shortcut has already been registered."); } }