Beispiel #1
0
 /// <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;
 }
Beispiel #2
0
 /// <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);
 }
Beispiel #3
0
 /// <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());
     }
 }
Beispiel #4
0
 public bool Remove(Hotkey item)
 {
     return Unregister(item);
 }
Beispiel #5
0
        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.");
        }
Beispiel #6
0
 public void Insert(int index, Hotkey item)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #7
0
 public bool Contains(Hotkey item)
 {
     return Hotkeys.ContainsValue(item);
 }
Beispiel #8
0
 public void CopyTo(Hotkey[] array, int arrayIndex)
 {
     Hotkeys.Values.CopyTo(array, arrayIndex);
 }
Beispiel #9
0
 public void Add(Hotkey item)
 {
     if (Hotkeys.ContainsValue(item))
         throw new ArgumentException("That Hotkey is already registered.");
     Register(item);
 }
Beispiel #10
0
 public void Insert(int index, Hotkey item)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #11
0
 public bool Remove(Hotkey item)
 {
     return(Unregister(item));
 }
Beispiel #12
0
 public bool Contains(Hotkey item)
 {
     return(Hotkeys.ContainsValue(item));
 }
Beispiel #13
0
 /// <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);
 }