public HotkeyInfo(Keys key, HotkeyModifiersKeys modifierKey, HotkeyModifiersKeys modifierKey2) { this.Key = key; this.ModifierKey = modifierKey; this.ModifierKey2 = modifierKey2; }
public HotkeyInfo(Keys key, HotkeyModifiersKeys modifierKey) : this(key, modifierKey, HotkeyModifiersKeys.None) { }
/// <summary> /// Unregister a hotkey. /// </summary> /// <param name="key">The hotkey to unregister.</param> /// <param name="modifier">The modfier of the hotkey.</param> /// <param name="modifier2">The modfier of the hotkey.</param> public void UnregisterHotkey(Keys key, HotkeyModifiersKeys modifier, HotkeyModifiersKeys modifier2) { var tempList = new Dictionary<int, HotkeyInfo>(registeredHotkeys); foreach (var entry in tempList) { if (entry.Value.Key == key && entry.Value.ModifierKey == modifier && entry.Value.ModifierKey2 == modifier2) { NativeMethods.UnregisterHotKey(this.windowHandle.Handle, entry.Key); registeredHotkeys.Remove(entry.Key); } } }
/// <summary> /// Register hotkey. /// </summary> /// <param name="key">The key to register as hotkey.</param> /// <param name="modifier">The modifier for the hotkey.</param> public void RegisterHotkey(Keys key, HotkeyModifiersKeys modifier) { this.RegisterHotkey(key, modifier, HotkeyModifiersKeys.None); }
/// <summary> /// Register hotkey. /// </summary> /// <param name="key">The key to register as hotkey.</param> /// <param name="modifier">The modifier for the hotkey.</param> /// <param name="modifier2">The second modifier for the hotkey.</param> public void RegisterHotkey(Keys key, HotkeyModifiersKeys modifier, HotkeyModifiersKeys modifier2) { if (!NativeMethods.RegisterHotKey(this.windowHandle.Handle, hotkeyId, (int)modifier | (int)modifier2, key.GetHashCode())) throw new InvalidOperationException("Could not register hotkey. Error code: " + NativeMethods.GetLastError()); registeredHotkeys.Add(hotkeyId, new HotkeyInfo(key, modifier, modifier2)); hotkeyId++; }