Exemplo n.º 1
0
        private void InitGlobalKey()
        {
            // If we're not enabled shut everything done asap
            if (!Enabled || !_active)
            {
                if (_globalKey != null)
                {
                    _globalKey.Enabled = false;
                    _globalKey         = null; // may as well collect the memory
                }

                // may not be false if !Enabled
                _active = false;

                return;
            }

            if (_globalKey == null)
            {
                _globalKey = new ManagedWinapi.Hotkey();
            }

            // make sure that we don't try to reregister the key midway updating
            // the combination
            if (_globalKey.Enabled)
            {
                _globalKey.Enabled = false;
            }

            _globalKey.WindowsKey = this.WindowsKey;
            _globalKey.Alt        = this.Alt;
            _globalKey.Ctrl       = this.Ctrl;
            _globalKey.Shift      = this.Shift;
            _globalKey.KeyCode    = ConvertInputKeyToFormsKeys(this.Key);

            _globalKey.HotkeyPressed += (s, e) => { Toast.ActionHookCallback(this); };

            try
            {
                _globalKey.Enabled = true;
            }
            catch (HotkeyAlreadyInUseException)
            {
                IsValid       = false;
                InvalidReason = "Hotkey is already in use by a different program";
            }
        }
Exemplo n.º 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);

            hotkey = new Hotkey();
            hotkey.Ctrl = true;
            hotkey.KeyCode = BlipFace.Properties.Settings.Default.HotKey;
            hotkey.HotkeyPressed += new EventHandler(hotkey_HotkeyPressed);
            BlipFace.Properties.Settings.Default.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Default_PropertyChanged);
            try
            {
                hotkey.Enabled = true;
            }
            catch (HotkeyAlreadyInUseException)
            {
                MessageBox.Show("HotKey jest już zajęty. Zmień w ustawieniach HotKey na inny.");
            }
        }
        public void RegisterHotKey(HotKeyDefinition definition, HotKeyPressedCallback callback)
        {
            try
            {
                var hotkey = new Hotkey
                {
                    Alt = definition.IncludeAltKey,
                    Ctrl = definition.IncludeCtrlKey,
                    Shift = definition.IncludeShiftKey,
                    WindowsKey = definition.IncludeWindowsKey,
                    KeyCode = definition.KeyCode
                };

                hotkey.HotkeyPressed += ((sender, e) => callback.Invoke());
                hotkey.Enabled = true;

                _hotkeys.Add(hotkey);
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 4
0
        private void RegisterHotKey(string hotkeyCombination, JukeboxCommand spotifyCommand)
        {
            var k = ParseKeyString(hotkeyCombination);

            if (k == Keys.None)
            {
                return;
            }

            var hotkey = new ManagedWinapi.Hotkey();

            if (hotkey.Enabled)
            {
                hotkey.Enabled = false;
            }

            hotkey.Alt   = hotkeyCombination.Contains("ALT");
            hotkey.Ctrl  = hotkeyCombination.Contains("CTRL") || hotkeyCombination.Contains("STRG");
            hotkey.Shift = hotkeyCombination.Contains("SHIFT");

            if (!hotkey.Alt && !hotkey.Ctrl && !hotkey.Shift)
            {
                hotkey.Dispose();
                return;
            }

            hotkey.KeyCode = k;

            hotkey.HotkeyPressed += (s, e) => {
                if (ReactOnEvent != null)
                {
                    ReactOnEvent(spotifyCommand);
                }
            };
            this._hotkeys.Add(hotkey);
        }
Exemplo n.º 5
0
        private void InitGlobalKey()
        {
            if (this._globalKey != null)
            {
                this._globalKey.HotkeyPressed -= this.GlobalKey_HotkeyPressed;
            }

            ToggleMouseHotkeyHook(this, false);

            // If we're not enabled shut everything down asap
            if (!this.Enabled || !this.Active)
            {
                if (this._globalKey != null)
                {
                    this._globalKey.Enabled = false;
                    this._globalKey         = null; // may as well collect the memory
                }

                // May not be false if !Enabled
                this._active = false;

                return;
            }

            if (this.KeyOrButton == null)
            {
                return;
            }

            if (this.KeyOrButton.IsKey)
            {
                // Standard global Hotkey

                if (!this.KeyOrButton.Key.HasValue)
                {
                    return;
                }

                if (this._globalKey == null)
                {
                    this._globalKey = new ManagedWinapi.Hotkey();
                }

                // Make sure that we don't try to re-register the key midway updating the combination.
                if (this._globalKey.Enabled)
                {
                    this._globalKey.Enabled = false;
                }

                this._globalKey.Shift      = this.Shift;
                this._globalKey.Ctrl       = this.Ctrl;
                this._globalKey.Alt        = this.Alt;
                this._globalKey.WindowsKey = this.WindowsKey;
                this._globalKey.KeyCode    = ConvertInputKeyToFormsKeys(this.KeyOrButton.Key.Value);

                if (this._globalKey.KeyCode == Keys.None)
                {
                    this._globalKey.Dispose();
                    this._globalKey = null;
                    return;
                }

                this._globalKey.HotkeyPressed += this.GlobalKey_HotkeyPressed;

                try
                {
                    this._globalKey.Enabled = true;
                }
                catch (HotkeyAlreadyInUseException e)
                {
                    this.IsValid       = false;
                    this.InvalidReason = "Hotkey is already in use by a different program";

                    logger.Warn($"Hotkey already in use: {this.HumanReadableKey}", e);
                }
            }
            else if (this.KeyOrButton.MouseButton.HasValue)
            {
                // Mouse "hotkey"

                if (this._globalKey != null)
                {
                    this._globalKey.HotkeyPressed -= this.GlobalKey_HotkeyPressed;
                }
                this._globalKey?.Dispose();

                if (registeredMouseHooks.Any(h => h.Shift == this.Shift && h.Ctrl == this.Ctrl && h.Alt == this.Alt && h.WindowsKey == this.WindowsKey &&
                                             h.KeyOrButton?.MouseButton == this.KeyOrButton?.MouseButton))
                {
                    this.IsValid       = false;
                    this.InvalidReason = "Hotkey is already in use";
                }
                else
                {
                    ToggleMouseHotkeyHook(this, true);
                }
            }
        }
Exemplo n.º 6
0
 private void RegisterHotkey()
 {
     Hotkey _Hotkey = new Hotkey();
     _Hotkey.WindowsKey = true;
     _Hotkey.KeyCode = System.Windows.Forms.Keys.C;
     _Hotkey.HotkeyPressed += new EventHandler(Hotkey_HotkeyPressed);
     try
     {
         _Hotkey.Enabled = true;
     }
     catch { throw new Exception("key already token"); }
 }
Exemplo n.º 7
0
        private void RegisterHotKey(string hotkeyCombination, JukeboxCommand spotifyCommand)
        {
            var k = ParseKeyString(hotkeyCombination);
            if (k == Keys.None)
                return;

            var hotkey = new ManagedWinapi.Hotkey();
            if (hotkey.Enabled)
                hotkey.Enabled = false;

            hotkey.Alt = hotkeyCombination.Contains("ALT");
            hotkey.Ctrl = hotkeyCombination.Contains("CTRL") || hotkeyCombination.Contains("STRG");
            hotkey.Shift = hotkeyCombination.Contains("SHIFT");

            if (!hotkey.Alt && !hotkey.Ctrl && !hotkey.Shift) {
                hotkey.Dispose();
                return;
            }

            hotkey.KeyCode = k;

            hotkey.HotkeyPressed += (s, e) => {
                if (ReactOnEvent != null)
                    ReactOnEvent(spotifyCommand);
            };
            this._hotkeys.Add(hotkey);
        }