Пример #1
0
        private void SwitchModeCommon(string modeName, bool isSilent = false)
        {
            bool before = _currentKeybinds.IsEnabledWindowsKeybinds;

            if (_keybindsDic.ContainsKey(modeName))
            {
                _currentKeybinds = _keybindsDic.FirstOrDefault(x => x.Key == modeName).Value;
            }
            else
            {
                if (_keybindsDic.ContainsKey(_settings.Mode))
                {
                    _currentKeybinds = _keybindsDic[_settings.Mode];
                }
                else
                {
                    _currentKeybinds = _keybindsDic[Consts.DefaultMode];
                }
            }
            var keybinds = _currentKeybinds.Keybinds;

            if (_currentKeybinds.IsPrefix)
            {
                _command = (_, keysState) =>
                {
                    if (keybinds.Contains(keysState))
                    {
                        keybinds.Execute(keysState, false);
                    }
                    SwitchMode(_settings.Mode, true);
                    _command = null;
                };
            }

            if (before && !_currentKeybinds.IsEnabledWindowsKeybinds)
            {
                if (_currentKeySet.Keys.Any(x => x.IsModifiersKey()))
                {
                    var keys = _currentKeySet.Keys.Where(x => x.IsModifiersKey()).ToArray();
                    KeyboardAPI.KeyboardOperation.KeyUp(keys);
                }
            }
        }
Пример #2
0
        public void LoadKeybinds(IKeyboardPluginContext context)
        {
            _keybindsDic.Clear();
            foreach (var keybinds in _settings.KeybindsInMode)
            {
                var defaultKeybinds = context.Keybinds;
                defaultKeybinds = KeyboardAPI.CreateKeybindManager();
                var keybindStorage = new KeybindStorage();
                var oneShotDefined = new Dictionary <KeySet, bool>();
                foreach (var keybind in keybinds.Value.Keybinds)
                {
                    if (keybind.InputKeys == null)
                    {
                        continue;
                    }
                    var keyset           = new KeySet(keybind.InputKeys);
                    var canDefineOneShot = keybind.CanDefineOneShot;
                    if (canDefineOneShot)
                    {
                        oneShotDefined.Add(keyset, canDefineOneShot);
                    }
                    switch (keybind.Type)
                    {
                    case CommandType.SwapKey:
                        if (canDefineOneShot)
                        {
                            keybindStorage.OneShotKeybinds.Add(keyset, () =>
                            {
                                var keys = keybind.OneShot;
                                if (_stateController.Mode == Mode.Visual && ContainsMovingKey(keys))
                                {
                                    KeyboardAPI.KeyboardOperation.SendKeys(new[] { Key.RightShift }.Concat(keys).ToArray());
                                    return;
                                }
                                KeyboardAPI.KeyboardOperation.SendKeys(keys);
                            }, KeyState.Down, true);
                        }
                        defaultKeybinds.Add(keyset, () =>
                        {
                            var keys     = keybind.OutputKeys;
                            var isVisual = _stateController.Mode == Mode.Visual && ContainsMovingKey(keys);
                            if (isVisual)
                            {
                                keys = new[] { Key.RightShift }.Concat(keys).ToArray();
                            }
                            KeyboardAPI.KeyboardOperation.KeyDown(keys);
                            if (isVisual)
                            {
                                KeyboardAPI.KeyboardOperation.KeyUp(Key.RightShift);
                            }
                        }, KeyState.Down, true);
                        defaultKeybinds.Add(keyset, () =>
                        {
                            var keys = keybind.OutputKeys;
                            KeyboardAPI.KeyboardOperation.KeyUp(keys);
                        }, KeyState.Up, true);
                        break;

                    case CommandType.RunEmbeddedCommand:
                        defaultKeybinds.Add(keyset, ParseCommand(keybind.CommandText, keybind.InputKeys), KeyState.Down, true);
                        break;

                    case CommandType.RunUIAssistantCommand:
                        defaultKeybinds.Add(keyset, () =>
                        {
                            var command = keybind.CommandText;
                            if (KeybindsManiacs.UIAssistantAPI.PluginManager.Exists(command))
                            {
                                KeybindsManiacs.UIAssistantAPI.PluginManager.Execute(command);
                            }
                            else
                            {
                                UIAssistantAPI.NotificationAPI.NotifyWarnMessage("Plugin Error", string.Format(KeybindsManiacs.UIAssistantAPI.LocalizationAPI.Localize(TextID.CommandNotFound), command));
                            }
                        }, KeyState.Down, true);
                        break;

                    //case CommandType.RunExtensionCommand:
                    //    break;
                    default:
                        break;
                    }
                }
                keybindStorage.IsEnabledWindowsKeybinds = keybinds.Value.IsEnabledWindowsKeybinds;
                keybindStorage.IsPrefix       = keybinds.Value.IsPrefix;
                keybindStorage.OneShotDefined = oneShotDefined;
                keybindStorage.Keybinds       = defaultKeybinds;
                _keybindsDic.Add(keybinds.Key, keybindStorage);
            }
            SwitchMode(_settings.Mode, true);
        }