private void lkOK_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { HotKey.Set(hotkey); if (OnHotkeyChanged == null) { return; } OnHotkeyChanged.Invoke(hotkey); }
protected override void OnKeyDown(KeyEventArgs e) { e.SuppressKeyPress = true; Keys modifierKeys = e.Modifiers; Keys pressedKey = e.KeyData ^ modifierKeys; bool deleting = pressedKey == Keys.Escape || pressedKey == Keys.Delete || pressedKey == Keys.Back; if (deleting) { Text = "None"; } else { Text = ""; if ((modifierKeys & Keys.Control) > 0) { Text += "Ctrl + "; } if ((modifierKeys & Keys.Alt) > 0) { Text += "Alt + "; } if ((modifierKeys & Keys.Shift) > 0) { Text += "Shift + "; } if ((modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0) { Text += "Win + "; } if (Hotkey.IsValidKey(pressedKey)) { Text += (char)pressedKey; } } if (deleting) { Hotkey.Key = 0; Hotkey.Control = false; Hotkey.Alt = false; Hotkey.Shift = false; Hotkey.Win = false; HotkeyJustSet = true; _InWaitingKey = false; SetBackColor(); OnHotkeyChanged?.Invoke(this, null); } else if ((!RequireModifier || modifierKeys != Keys.None) && Hotkey.IsValidKey(pressedKey)) { Hotkey.Key = (int)pressedKey; Hotkey.Control = (modifierKeys & Keys.Control) > 0; Hotkey.Alt = (modifierKeys & Keys.Alt) > 0; Hotkey.Shift = (modifierKeys & Keys.Shift) > 0; Hotkey.Win = (modifierKeys & Keys.LWin) > 0 || (modifierKeys & Keys.RWin) > 0; HotkeyJustSet = true; _InWaitingKey = false; SetBackColor(); OnHotkeyChanged?.Invoke(this, null); } else { _InWaitingKey = true; SetBackColor(); } }