protected override void OnClosed(EventArgs e) { _source?.RemoveHook(HwndHook); HotKeyApi.UnregisterHotKey(_windowHandle, HotKeyApi.ActivateHotKeyId); base.OnClosed(e); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); _windowHandle = new WindowInteropHelper(this).Handle; _source = HwndSource.FromHwnd(_windowHandle); _source?.AddHook(HwndHook); HotKeyApi.RegisterHotKey(_windowHandle, HotKeyApi.ActivateHotKeyId, HotKeyApi.ModAlt, HotKeyApi.ZKey); }