Beispiel #1
0
 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.ModifierKeys, key.key)) {
         key.id = id;
         hotkeys.Add(id, key);
         ObservableHotkeys.Add(key);
     }
     else Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
 }
Beispiel #2
0
 public void Unregister(Hotkey key)
 {
     int index = IndexOf(key);
     if (index > 0) {
         if (NativeMethods.UnregisterHotKey(handle, index)) {
             hotkeys.Remove(index);
             ObservableHotkeys.Remove(key);
         }
         else Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
     }
 }
Beispiel #3
0
        private int IndexOf(Hotkey item)
        {
            if (item.id > 0 && hotkeys.ContainsKey(item.id))
                return item.id;
            if (hotkeys.ContainsValue(item)) {
                foreach (var k in hotkeys) {
                    if (item.Equals(k.Value)) {
                        item.id = k.Value.id;
                        return item.id;
                    }
                }
            }

            throw new ArgumentOutOfRangeException(string.Format("The hotkey \"{0}\" is not in this hotkey manager.", item));
        }
Beispiel #4
0
 public Hotkeys(Hotkey displayHotKey)
     : this()
 {
     DisplayHotKey = displayHotKey;
 }