コード例 #1
0
        private void RegisterHotKeyUp(ref GlobalHotKey globalHotKey, HotKeyCombination hotKeyCombination, TextBox textBox, KeyEventArgs e)
        {
            try
            {
                var pressedKeys = Keys.GetPressdKeys();

                pressedKeys = Keys.ClearRepeatedKeys(pressedKeys);

                pressedKeys = Keys.ClearMousKeys(pressedKeys);

                string str = _EmptyHKString;
                if (pressedKeys.Length == 0)
                {
                    Keyboard.ClearFocus();

                    if (hotKeyCombination.IsInitialized)
                    {
                        str = hotKeyCombination.CombinationKeysName();

                        if (globalHotKey != null)
                        {
                            _HotKeyManager.RemoveGlobalHotKey(globalHotKey);
                        }
                        else
                        {
                            int t = 0;
                            t++;
                        }

                        var k = Keys.ConvertFromWpfKey(hotKeyCombination.NormalKey);
                        globalHotKey = new GlobalHotKey(hotKeyCombination.Name, hotKeyCombination.ModifierKey, k);

                        _HotKeyManager.AddGlobalHotKey(globalHotKey);

                        textBox.Text = str;
                    }
                    else
                    {
                        if (globalHotKey != null)
                        {
                            _HotKeyManager.RemoveGlobalHotKey(globalHotKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
コード例 #2
0
        private void RegisterHotKeyUp(ref GlobalHotKey globalHotKey, HotKeyCombination hotKeyCombination, KeyEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            try
            {
                var pressedKeys = Keys.GetPressdKeys();

                pressedKeys = Keys.ClearRepeatedKeys(pressedKeys);

                pressedKeys = Keys.ClearMousKeys(pressedKeys);

                if (pressedKeys.Length == 0)
                {
                    Keyboard.ClearFocus();

                    if (hotKeyCombination.IsInitialized)
                    {
                        if (globalHotKey != null)
                        {
                            _HotKeyManager.RemoveGlobalHotKey(globalHotKey);
                        }

                        var k = Keys.ConvertFromWpfKey(hotKeyCombination.NormalKey);
                        globalHotKey = new GlobalHotKey(hotKeyCombination.Name, hotKeyCombination.ModifierKey, k);

                        _HotKeyManager.AddGlobalHotKey(globalHotKey);
                    }
                    else
                    {
                        if (globalHotKey != null)
                        {
                            _HotKeyManager.RemoveGlobalHotKey(globalHotKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
コード例 #3
0
        private void RegisterHotKeyDown(ref GlobalHotKey globalHotKey, HotKeyCombination hotKeyCombination, TextBox textBox, KeyEventArgs e)
        {
            try
            {
                var _key = Helper.RealKey(e);

                var pressedKeys = Keys.GetPressdKeys();

                pressedKeys = Keys.ClearRepeatedKeys(pressedKeys);

                pressedKeys = Keys.ClearMousKeys(pressedKeys);

                if (pressedKeys.Length <= 1)
                {
                    hotKeyCombination.ClearKeys();
                }

                hotKeyCombination.AddKey(_key);

                string str = _EmptyHKString;
                if (hotKeyCombination.IsInitialized)
                {
                    str = hotKeyCombination.CombinationKeysName();

                    textBox.Text = str;
                }
                else
                {
                    if (globalHotKey != null)
                    {
                        _HotKeyManager.RemoveGlobalHotKey(globalHotKey);
                    }
                }
                textBox.Text = str;
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
コード例 #4
0
        private void RegisterHotKeyDown(ref GlobalHotKey globalHotKey, HotKeyCombination hotKeyCombination, KeyEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            try
            {
                var _key = Helper.RealKey(e);

                var pressedKeys = Keys.GetPressdKeys();

                pressedKeys = Keys.ClearRepeatedKeys(pressedKeys);

                pressedKeys = Keys.ClearMousKeys(pressedKeys);

                if (pressedKeys.Length <= 1)
                {
                    hotKeyCombination.ClearKeys();
                }

                hotKeyCombination.AddKey(_key);

                if (!hotKeyCombination.IsInitialized)
                {
                    if (globalHotKey != null)
                    {
                        _HotKeyManager.RemoveGlobalHotKey(globalHotKey);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }