Exemplo n.º 1
0
        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);
                    }
                }
            }));
        }
Exemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                HotkeyInterop.DeleteAtom((uint)Id);
            }

            _disposed = true;
        }
Exemplo n.º 3
0
        private async void Initialize()
        {
            WindowInteropHelper interopHelper = new WindowInteropHelper(this);

            _windowHandle = interopHelper.EnsureHandle();

            _hotkeyInterop = new HotkeyInterop();
            _hotkeyInterop.HotkeyPressed += OnHotkeyPressed;
            OnHotkeySettingsChanged();


            EnsureTaskBarIcon();
            await InitializeAppServiceConnection();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates hotkey for hooked mode.
 /// </summary>
 public Hotkey(KeyCombo keyCombo, Action action)
 {
     KeyCombo = keyCombo;
     _action  = action;
     Id       = (int)HotkeyInterop.AddAtom(Guid.NewGuid().ToString());
 }