internal IntPtr HandleHotkeyMessage( IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled, out Hotkey hotkey) { hotkey = null; if (msg == WmHotkey) { int id = wParam.ToInt32(); string name; if (_hotkeyNames.TryGetValue(id, out name)) { hotkey = _hotkeys[name]; var handler = hotkey.Handler; if (handler != null) { var e = new HotkeyEventArgs(name); handler(this, e); handled = e.Handled; } } } return IntPtr.Zero; }
private static void UnregisterHotkey(Hotkey hotkey) { try { HotkeyManager.Current.Remove(hotkey.Guid.ToString()); } catch { // ignored } }
internal void AddOrReplace(string name, uint virtualKey, HotkeyFlags flags, EventHandler<HotkeyEventArgs> handler) { var hotkey = new Hotkey(virtualKey, flags, handler); lock (_hotkeys) { Remove(name); _hotkeys.Add(name, hotkey); _hotkeyNames.Add(hotkey.Id, name); if (_hwnd != IntPtr.Zero) hotkey.Register(_hwnd, name); } }
public static void RegisterHotkey(Hotkey hotkey, Action callback) { if (hotkey.Key == Key.None) return; RemoveHotkey(hotkey); Hotkeys.Add(new Tuple<Hotkey, Action>(hotkey, callback)); try { HotkeyManager.Current.AddOrReplace(hotkey.Guid.ToString(), hotkey.Key, hotkey.ModifierKeys, !hotkey.CanRepeat, (sender, args) => OnHotkey(hotkey.Key, hotkey.ModifierKeys)); } catch (HotkeyAlreadyRegisteredException) { } }
public static void RemoveHotkey(Hotkey hotkey) => RemoveHotkey(hotkey.Guid);