Exemplo n.º 1
0
        internal void Notify(KeyNotifyEventArgs keyNotifyEventArgs)
        {
            try
            {
                Logger.Trace("Key notified: UnitId={0}, IsPressed={1}, Key={2}, AllKeys=[{3}]", keyNotifyEventArgs.UnitId, keyNotifyEventArgs.IsPressed, keyNotifyEventArgs.Key, string.Join(",", keyNotifyEventArgs.AllKeys));
                if (keyNotifyEventArgs.UnitId != UnitId)
                {
                    return;
                }
                if (!(Context is IUiEngine engine))
                {
                    return;
                }
                var commands = Commands.Where(c =>
                                              c.Key == keyNotifyEventArgs.Key &&
                                              keyNotifyEventArgs.IsPressed == (c.ActiveOn == ActiveOnEnum.Press) &&
                                              (c.Required < 0 || keyNotifyEventArgs.AllKeys.Contains(c.Required))).ToList();
                var command = commands.FirstOrDefault(c => c.Required >= 0) ?? commands.FirstOrDefault(); //executes single command, the one with modifier has higher priority
                if (command == null)
                {
                    return;
                }
                switch (command.CommandTarget)
                {
                case CommandTargetEnum.Engine:
                    ExecuteOnEngine(engine, command.Method, command.Parameter);
                    break;

                case CommandTargetEnum.Keyboard:
                    ExecuteOnKeyboard(command.Method);
                    break;

                case CommandTargetEnum.SelectedEvent:
                    ExecuteOnSelectedEvent(engine.SelectedEvent, command.Method);
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Exemplo n.º 2
0
 private void KeyNotified(object sender, KeyNotifyEventArgs keyNotifyEventArgs)
 {
     Array.ForEach(_plugins, plugin => plugin.Notify(keyNotifyEventArgs));
 }