/// <summary>Unregister the specified hotkey if it's in our collection /// </summary> /// <param name="key">The key.</param> /// <returns>True if we successfully unregister the hotkey.</returns> public bool Unregister(Hotkey key) { int id = IndexOf(key); if (id > 0) { if (NativeMethods.UnregisterHotKey(handle, id)) { Hotkeys.Remove(id); observableHotkeys.Remove(key); return true; } else { int lastError = Marshal.GetLastWin32Error(); Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); return false; } } else return false; }
/// <summary> /// Determines if the specified <see cref="T:Hotkey"/> is equal to this one. /// </summary> /// <param name="key">The <see cref="T:Hotkey"/>.</param> /// <returns>True if the key and modifiers are the same</returns> public bool Equals(Hotkey key) { return (key.Modifiers == Modifiers && key.Key == Key); }
/// <summary>Register a new hotkey, and add it to our collection /// </summary> /// <param name="key">A reference to the Hotkey.</param> /// <returns>True if the hotkey was set successfully.</returns> public void Register(Hotkey key) { if (handle == IntPtr.Zero) throw new InvalidOperationException("You can't register hotkeys until your Window is loaded."); if (NativeMethods.RegisterHotKey(handle, ++id, key.Modifiers, key.Key)) { key.Id = id; Hotkeys.Add(id, key); observableHotkeys.Add(key); } else { int lastError = Marshal.GetLastWin32Error(); Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); } }
public bool Remove(Hotkey item) { return Unregister(item); }
public int IndexOf(Hotkey item) { if (item.Id > 0 && Hotkeys.ContainsKey(item.Id)) return item.Id; else if (Hotkeys.ContainsValue(item)) { foreach (KeyValuePair<int, Hotkey> k in Hotkeys) { if (item.Equals(k.Value)) { item.Id = k.Value.Id; return item.Id; } } } throw new ArgumentOutOfRangeException("The hotkey \"{0}\" is not in this hotkey manager."); }
public void Insert(int index, Hotkey item) { throw new Exception("The method or operation is not implemented."); }
public bool Contains(Hotkey item) { return Hotkeys.ContainsValue(item); }
public void CopyTo(Hotkey[] array, int arrayIndex) { Hotkeys.Values.CopyTo(array, arrayIndex); }
public void Add(Hotkey item) { if (Hotkeys.ContainsValue(item)) throw new ArgumentException("That Hotkey is already registered."); Register(item); }
public bool Remove(Hotkey item) { return(Unregister(item)); }
public bool Contains(Hotkey item) { return(Hotkeys.ContainsValue(item)); }
/// <summary> /// Determines if the specified <see cref="T:Hotkey"/> is equal to this one. /// </summary> /// <param name="key">The <see cref="T:Hotkey"/>.</param> /// <returns>True if the key and modifiers are the same</returns> public bool Equals(Hotkey key) { return(key.Modifiers == Modifiers && key.Key == Key); }