private void OnHotkeySettingsChanged() { Dispatcher.Invoke(new Action(() => { // Following code must be run on thread which created HotkeyInterop->HotkeyHook->NativeWindow.Handle. HotkeyInterop hotkeyInterop = _hotkeyInterop; hotkeyInterop.Unregister(HOTKEY_SLEEP_ID); hotkeyInterop.Unregister(HOTKEY_SLEEP_ALT_ID); hotkeyInterop.Unregister(HOTKEY_DISPLAY_OFF_ID); if (SettingsHelper.IsHotkeysEnabled) { Hotkey sleepHotkey = SettingsHelper.SleepHotkey; if (sleepHotkey.IsSet) { hotkeyInterop.Register(HOTKEY_SLEEP_ID, sleepHotkey); } Hotkey sleepAlternativeHotkey = SettingsHelper.SleepAlternativeHotkey; if (sleepAlternativeHotkey.IsSet) { hotkeyInterop.Register(HOTKEY_SLEEP_ALT_ID, sleepAlternativeHotkey); } Hotkey displayOffHotkey = SettingsHelper.DisplayOffHotkey; if (displayOffHotkey.IsSet) { hotkeyInterop.Register(HOTKEY_DISPLAY_OFF_ID, displayOffHotkey); } } })); }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { HotkeyInterop.DeleteAtom((uint)Id); } _disposed = true; }
private async void Initialize() { WindowInteropHelper interopHelper = new WindowInteropHelper(this); _windowHandle = interopHelper.EnsureHandle(); _hotkeyInterop = new HotkeyInterop(); _hotkeyInterop.HotkeyPressed += OnHotkeyPressed; OnHotkeySettingsChanged(); EnsureTaskBarIcon(); await InitializeAppServiceConnection(); }
/// <summary> /// Creates hotkey for hooked mode. /// </summary> public Hotkey(KeyCombo keyCombo, Action action) { KeyCombo = keyCombo; _action = action; Id = (int)HotkeyInterop.AddAtom(Guid.NewGuid().ToString()); }