private void Initialize(Window window, HotKeyMods mod, uint key) { var interopHelp = new WindowInteropHelper(window); _handle = interopHelp.Handle; _source = HwndSource.FromHwnd(_handle); _source.AddHook(HwndHook); _finalKey = key; RegisterHotKey(_handle, _hotId, (uint)mod, key); window.Closed += (_, __) => Dispose(); }
/// <summary> /// Constructor for a new hotkey /// </summary> /// <param name="window">The current WPF window.</param> /// <param name="act">What to execute when the hot key is called</param> /// <param name="mod">The first optional key combination </param> /// <param name="key">The final key, binded with <paramref name="mod"/></param> public HotKeyRegisterer(Window window, EventHandler act, HotKeyMods mod, uint key) { _idCount++; _hotId += _idCount; OnTriggerFunction += act; if (!window.IsLoaded) { window.Loaded += (_, __) => Initialize(window, mod, key); return; } Initialize(window, mod, key); }
/// <summary> /// Constructor for a new hotkey /// </summary> /// <param name="window">The current WinForms window.</param> /// <param name="act">What to execute when the hot key is called</param> /// <param name="mod">The first optional key combination </param> /// <param name="key">The final key, bound with <paramref name="mod"/></param> /// <param name="disposeOnClosing">Tells whether or not the registerer should dispose when the form closes.</param> public HotKeyRegisterer(Form window, EventHandler act, HotKeyMods mod, uint key, bool disposeOnClosing = true) { _idCount++; _hotKeyUniqueId += _idCount; OnTriggerFunction += act; _finalKey = key; RegisterHotKey(window.Handle, _hotKeyUniqueId, (uint)mod, key); if (disposeOnClosing) { window.Closed += (sender, args) => Dispose(); } }
/// <summary> /// Constructor for a new hotkey /// </summary> /// <param name="window">The current WPF window.</param> /// <param name="act">What to execute when the hot key is called</param> /// <param name="mod">The first optional key combination </param> /// <param name="key">The final key, binded with <paramref name="mod"/></param> public HotKeyRegisterer(System.Windows.Window window, Action act, HotKeyMods mod, uint key) { idCount++; hotID += idCount; OnTriggerFunction += act; var interopHelp = new WindowInteropHelper(window); handle = interopHelp.Handle; source = HwndSource.FromHwnd(handle); source.AddHook(HwndHook); finalKey = key; RegisterHotKey(handle, hotID, (uint)mod, key); }
/// <summary> /// Constructor for a new hotkey /// </summary> /// <param name="window">The current WPF window.</param> /// <param name="act">What to execute when the hot key is called</param> /// <param name="mod">The first optional key combination </param> /// <param name="key">The final key using the ConsoleKey enum, for more keys, use the other constructor. Binded with <paramref name="mod"/></param> public HotKeyRegisterer(System.Windows.Window window, Action act, HotKeyMods mod, ConsoleKey key) : this(window, act, mod, (uint)key) { }
/// <inheritdoc /> public HotKeyRegisterer(Window window, Action act, HotKeyMods mod, uint key) : this(window, (_, __) => act(), mod, key) { }
/// <inheritdoc /> public HotKeyRegisterer(Window window, Action act, HotKeyMods mod, ConsoleKey key) : this(window, (_, __) => act(), mod, (uint)key) { }
/// <summary> /// Constructor for a new hotkey /// </summary> /// <param name="window">The current WPF window.</param> /// <param name="act">What to execute when the hot key is called</param> /// <param name="mod">The first optional key combination </param> /// <param name="key">The final key using the ConsoleKey enum, for more keys, use the other constructor. Bound with <paramref name="mod"/></param> public HotKeyRegisterer(Window window, EventHandler act, HotKeyMods mod, ConsoleKey key) : this(window, act, mod, (uint)key) { }
protected HotKeyRegisterer AddHotKeyRegisterer(Action act, HotKeyMods mod, uint key) => AddHotKeyRegisterer(new HotKeyRegisterer(this, act, mod, key));
protected HotKeyRegisterer AddHotKeyRegisterer(EventHandler act, HotKeyMods mod, uint key) => AddHotKeyRegisterer(new HotKeyRegisterer(this, act, mod, key));
/// <inheritdoc/> public HotKeyRegisterer(Form window, Action act, HotKeyMods mod, uint key, bool disposeOnClosing = true) : this(window, (_, __) => act(), mod, key, disposeOnClosing) { }
/// <summary> /// Constructor for a new hot key /// </summary> /// <param name="window">The current WinForms window.</param> /// <param name="act">What to execute when the hot key is called</param> /// <param name="mod">The first optional key combination </param> /// <param name="key">The final key using the ConsoleKey enum, for more keys, use the other constructor. Bound with <paramref name="mod"/></param> /// <param name="disposeOnClosing">Tells whether or not the registerer should dispose when the form closes.</param> public HotKeyRegisterer(Form window, EventHandler act, HotKeyMods mod, ConsoleKey key, bool disposeOnClosing = true) : this(window, act, mod, (uint)key, disposeOnClosing) { }