Ejemplo n.º 1
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            try
            {
                // Load window placement details for previous application session from application settings
                // Note - if window was closed on a monitor that is now disconnected from the computer,
                //        SetWindowPlacement will place the window onto a visible monitor.

                if (PreferencesFile.IsSettingAvailable("ControlCenter", "WindowLocation"))
                {
                    WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
                    wp.normalPosition = PreferencesFile.LoadSetting("ControlCenter", "WindowLocation",
                                                                    new RECT(0, 0, (int)Width, (int)Height));
                    wp.length  = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                    wp.flags   = 0;
                    wp.showCmd = (wp.showCmd == NativeMethods.SW_SHOWMINIMIZED
                        ? NativeMethods.SW_SHOWNORMAL
                        : wp.showCmd);
                    IntPtr hwnd = new WindowInteropHelper(this).Handle;
                    NativeMethods.SetWindowPlacement(hwnd, ref wp);
                }

                if (!Enum.TryParse(Preferences.HotKeyModifiers, out ModifierKeys mods))
                {
                    HotKeyDescription = "None";
                    return;
                }
                if (!Enum.TryParse(Preferences.HotKey, out Keys hotKey))
                {
                    HotKeyDescription = "None";
                    return;
                }
                if (hotKey != Keys.None)
                {
                    _hotkey = new HotKey(mods, hotKey, this);
                    _hotkey.HotKeyPressed += new Action <HotKey>(HotKeyPressed);
                    HotKeyDescription      = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) +
                                             _hotkey.Key.ToString();
                }
                else
                {
                    HotKeyDescription = "None";
                }
            }
            catch (System.Exception ex)
            {
                ConfigManager.LogManager.LogError("exception thrown during hotkey initialization", ex);
                RemoveHotkey();
            }
        }
Ejemplo n.º 2
0
        private void SetHotkey_Click(object sender, RoutedEventArgs e)
        {
            HotKeyDetector detector = new HotKeyDetector();

            detector.Owner = this;
            detector.ShowDialog();

            if (_hotkey != null)
            {
                _hotkey.UnregisterHotKey();
                _hotkey.Dispose();
            }

            _hotkey = new HotKey(detector.Modifiers, detector.Key, _helper.Handle);
            _hotkey.HotKeyPressed += HotKeyPressed;

            Preferences.HotKeyModifiers = detector.Modifiers.ToString();
            Preferences.HotKey          = detector.Key.ToString();
            HotKeyDescription           = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) + _hotkey.Key.ToString();
        }
Ejemplo n.º 3
0
        private void SetHotkey_Click(object sender, RoutedEventArgs e)
        {
            HotKeyDetector detector = new HotKeyDetector();

            detector.Owner = this;
            detector.ShowDialog();

            if (_hotkey != null)
            {
                _hotkey.UnregisterHotKey();
                _hotkey.Dispose();
            }

            _hotkey = new HotKey(detector.Modifiers, detector.Key, _helper.Handle);
            _hotkey.HotKeyPressed += new Action <HotKey>(HotKeyPressed);

            ConfigManager.SettingsManager.SaveSetting("ControlCenter", "HotKeyModifiers", detector.Modifiers.ToString());
            ConfigManager.SettingsManager.SaveSetting("ControlCenter", "HotKey", detector.Key.ToString());

            HotKeyDescription = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) + _hotkey.Key.ToString();
        }
Ejemplo n.º 4
0
        void ComponentDispatcher_ThreadPreprocessMessage(ref MSG msg, ref bool handled)
        {
            if (msg.message == NativeMethods.WM_KEYDOWN)
            {
                Modifiers = Modifiers | ModifierForVK((Keys)msg.wParam);
            }
            if (msg.message == NativeMethods.WM_KEYUP)
            {
                Keys         upKey = (Keys)msg.wParam;
                ModifierKeys mods  = ModifierForVK(upKey);
                if (mods != ModifierKeys.None)
                {
                    Modifiers = Modifiers & ~ModifierForVK(upKey);
                }
                else if (upKey != Keys.None)
                {
                    Key = upKey;
                    DispatcherTimer minizeTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 250), DispatcherPriority.Normal, TimedClose, Dispatcher);
                    minizeTimer.Start();
                }
            }

            HotKeyDescription = KeyboardEmulator.ModifierKeysToString(Modifiers) + Key.ToString();
        }