private void txtHotkey_KeyDown(object sender, KeyEventArgs e) { e.SuppressKeyPress = true; // Don't want to do anything if only a modifier key is pressed. // Modifiers Asian keys (kana, hanja, kanji etc) IME related keys (convert etc) Korean alt (process) Windows keys if (!((e.KeyValue >= 16 && e.KeyValue <= 18) || (e.KeyValue >= 21 && e.KeyValue <= 25) || (e.KeyValue >= 28 && e.KeyValue <= 31) || e.KeyValue == 229 || (e.KeyValue >= 91 && e.KeyValue <= 92))) { Win32.UnregisterHotKey(this.Handle, (int)hotkey); hotkey = e.KeyData; // Extract modifiers hotkeyNodifiers = 0; if ((e.Modifiers & Keys.Shift) != 0) { hotkeyNodifiers |= Win32.fsModifiers.Shift; } if ((e.Modifiers & Keys.Control) != 0) { hotkeyNodifiers |= Win32.fsModifiers.Control; } if ((e.Modifiers & Keys.Alt) != 0) { hotkeyNodifiers |= Win32.fsModifiers.Alt; } SetHotkey(); } }
private void UnsetHotkey() { Win32.UnregisterHotKey(this.Handle, (int)hotkey); btnHotkeyRemove.Enabled = false; }