예제 #1
0
 void RemoveHook()
 {
     _keyCommandDownActionToken?.Remove();
     _keyCommandDownActionToken = null;
     _keyCommandUpActionToken?.Remove();
     _keyCommandUpActionToken = null;
 }
예제 #2
0
        private void RunOrExplore(IKeyCommand keyCommand)
        {
            var command = keyCommand as IRunableKeyCommand;

            if (command != null)
            {
                try
                {
                    var thread = new Thread(() => command.Run(CurrentContext));
                    thread.Start();
                }
                catch (Exception ex)
                {
                    LogManager.Logger(GetType()).Error(ex.Message, ex);
                }
                OnCommandExecuted(EventArgs.Empty);
                return;
            }

            var group = keyCommand as IKeyCommandGroup;

            if (group != null)
            {
                stack.Push(group);
            }

            OnCommandListChanged(EventArgs.Empty);
        }
예제 #3
0
        private void RunOrExploreCommand(object sender, KeyEventArgs e)
        {
            IKeyCommand command = commandsList1.CurrentCommand();

            if (command != null)
            {
                e.Handled = true;
                mainModel.ExecuteOrExplore(command.KeyCode);
            }
        }
예제 #4
0
파일: Main.cs 프로젝트: metatool/metatool
        public ToolDemo(ICommandManager commandManager, IKeyboard keyboard, IConfig <Config> config)
        {
            CommandA = commandManager.Add(keyboard.OnDown(AK + A),
                                          e => { Logger.LogInformation($"{nameof(ToolDemo)}: Caps+A triggered!!!!!!!"); });
            CommandB = (Caps + B).OnDown(e => Logger.LogWarning("Caps+B pressed!!!"));

            Logger.LogInformation(config.CurrentValue.Option1);
            Logger.LogInformation(config.CurrentValue.Option2.ToString());
            RegisterCommands();
        }
예제 #5
0
        /// <summary>
        /// Zwraca true jeżeli komenda została wykonana i nalezy schować formę
        /// </summary>
        public bool ExecuteOrExplore(Keys keyCode)
        {
            IKeyCommand keyCommand = CommandsList.FirstOrDefault(kc => kc.KeyCode == keyCode);

            if (keyCommand != null)
            {
                RunOrExplore(keyCommand);
                return(true);
            }

            return(false);
        }
예제 #6
0
        public static IKeyCommand CreateCommand(ConfigCommand item)
        {
            var     manifest = GetCommandManifest(item.CommandType);
            IPlugin plugin   = Plugins.FirstOrDefault(p => p.NameSpace == manifest.NameSpace);

            if (plugin == null)
            {
                LogManager.Logger(typeof(ConfigurationHelper))
                .Error("Błąd tworzenia komendy. Nie znaleziono pluginu.");
                LogManager.Logger(typeof(ConfigurationHelper))
                .WarnFormat("Komenda [{0}] została pominięta.", item.Id);
                return(null);
            }

            try
            {
                IKeyCommand command = plugin.CreateCommand(
                    manifest.Command,
                    new KeyCommandConfig
                {
                    Id          = item.Id,
                    Description = item.Description,
                    Icon        = GetImage(item.IconPath),
                    Parameters  = item.Parameters,
                    KeyCode     = GetKeys(item.Key)
                });

                if (command != null)
                {
                    return(command);
                }

                LogManager.Logger(typeof(ConfigurationHelper))
                .Error("Błąd tworzenia komendy. Plugin nie zwrócił instancji.");
                LogManager.Logger(typeof(ConfigurationHelper))
                .WarnFormat("Komenda [{0}] została pominięta.", item.Id);
            }
            catch (Exception ex)
            {
                LogManager.Logger(typeof(ConfigurationHelper))
                .Error("Błąd tworzenia komendy", ex);
                LogManager.Logger(typeof(ConfigurationHelper))
                .WarnFormat("Komenda [{0}] została pominięta.", item.Id);
            }

            return(null);
        }
예제 #7
0
        void InstallHook()
        {
            if (_keyCommandDownActionToken == null)
            {
                _keyCommandDownActionToken = _key.OnDown(e =>
                {
                    if (!_isAlwaysOn.HasValue)
                    {
                        return;
                    }


                    if (_key == Keys.NumLock)
                    {
                        var on = Control.IsKeyLocked((Keys)_key);
                        if (on && !_isAlwaysOn.Value || !on && _isAlwaysOn.Value)
                        {
                            _valid = true;
                            return;
                        }


                        return;
                    }

                    if (_confirmAlwaysOnOffSate)
                    {
                        _confirmAlwaysOnOffSate = false;
                        var on = Control.IsKeyLocked((Keys)_key);
                        if (on && !_isAlwaysOn.Value || !on && _isAlwaysOn.Value)
                        {
                            _valid = true;
                            return;
                        }
                    }

                    e.Handled = true;
                }, e => !e.IsVirtual);
            }
            if (_keyCommandUpActionToken == null)
            {
                _keyCommandUpActionToken = _key.OnUp(e =>
                {
                    if (!_isAlwaysOn.HasValue)
                    {
                        return;
                    }

                    if (_key == Keys.NumLock)
                    {
                        if (_valid)
                        {
                            _valid = false;
                            return;
                        }

                        Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Send, (Action)(() =>
                                                                                                   InputSimu.Inst.Keyboard.KeyPress((VirtualKeyCode)(Keys)_key)));
                        return;
                    }

                    if (_valid)
                    {
                        _valid = false;
                        return;
                    }

                    e.Handled = true;
                }, e => !e.IsVirtual);
            }
        }
예제 #8
0
        public static IList <IKeyCommand> GetCommands(IDictionary <KeyCombination, IKeyCommand> globalCommands)
        {
            var result   = new List <IKeyCommand>();
            var commands = new Dictionary <string, IKeyCommand>();

            var configCommands = GetConfigCommands();

            foreach (var configCommand in configCommands)
            {
                IKeyCommand command = CreateCommand(configCommand);

                if (!String.IsNullOrWhiteSpace(configCommand.GlobalKey))
                {
                    globalCommands.Add(KeysHelper.GetKeyCombination(configCommand.GlobalKey), command);
                }

                if (command == null)
                {
                    LogManager.Logger(typeof(ConfigurationHelper))
                    .WarnFormat("Nie powiodło się u instancji komendy [{0}], nie odnalezione typu '{1}'.", configCommand.Id, configCommand.CommandType);
                    continue;
                }

                commands.Add(configCommand.Id, command);
            }

            foreach (var configCommand in configCommands)
            {
                var command = commands[configCommand.Id];
                if (string.IsNullOrEmpty(configCommand.Parent))
                {
                    result.Add(command);
                }
                else
                {
                    if (commands.ContainsKey(configCommand.Parent))
                    {
                        var group = commands[configCommand.Parent] as IKeyCommandGroup;
                        if (group != null)
                        {
                            group.SubCommands.Add(command);
                        }
                        else
                        {
                            LogManager.Logger(typeof(ConfigurationHelper))
                            .ErrorFormat("Komenda [{0}], nie implementuje interfejsu IKeyCommandGroup, nie można dodać potomka.", configCommand.Parent);
                            LogManager.Logger(typeof(ConfigurationHelper))
                            .WarnFormat("Komenda [{0}] została pominięta.", configCommand.Id);
                        }
                    }
                    else
                    {
                        LogManager.Logger(typeof(ConfigurationHelper))
                        .ErrorFormat("Komenda [{0}], nie istnieje, nie można dodać potomka.", configCommand.Parent);
                        LogManager.Logger(typeof(ConfigurationHelper))
                        .WarnFormat("Komenda [{0}] została pominięta.", configCommand.Id);
                    }
                }
            }

            return(result);
        }
예제 #9
0
 private void RegisterMainLevelCommand(IKeyCommand keyCommand)
 {
     rootCommand.SubCommands.Add(keyCommand);
 }