Exemple #1
0
        public IKeyboardCommandTrigger OnEvent(IHotkey hotkey, KeyEvent keyEvent,
                                               string stateTree = KeyStateTrees.Default)
        {
            if (keyEvent == KeyEvent.Hit)
            {
                return(OnHit(hotkey, stateTree));
            }

            var sequence = hotkey switch
            {
                ISequenceUnit sequenceUnit => new List <ICombination>()
                {
                    sequenceUnit.ToCombination().ToCombination()
                },
                ISequence seq => seq.ToList(),
                _ => throw new Exception("IHotkey should be ISequence or ISequenceUnit")
            };
            var trigger = new KeyboardCommandTrigger();
            var metaKey = Add(sequence, keyEvent,
                              new KeyCommand(trigger.OnExecute)
            {
                CanExecute = trigger.OnCanExecute
            }, stateTree) as MetaKey;

            trigger._metaKey = metaKey;
            return(trigger);
        }
        public static Task <IKeyEventArgs> UpAsync(this ISequenceUnit sequenceUnit, int timeout = -1, string description = "", string stateTree = KeyStateTrees.Default)
        {
            var combination = sequenceUnit.ToCombination();
            var command     = new KeyEventAsync();
            var trigger     = Keyboard.Up(combination, stateTree);

            CommandManager.Add(trigger, command.OnEvent, null, description);
            return(command.WaitAsync(timeout));
        }
        public static IKey  Hit(this ISequenceUnit sequenceUnit, Action <IKeyEventArgs> execute,
                                Predicate <IKeyEventArgs> canExecute, string description, string stateTree = KeyStateTrees.Default)
        {
            var combination      = sequenceUnit.ToCombination();
            var trigger          = Keyboard.Hit(combination, stateTree);
            var token            = CommandManager.Add(trigger, execute, canExecute, description);
            var keyboardInternal = (IKeyboardInternal)Keyboard;

            return(keyboardInternal.GetToken(token, trigger));
        }
        public IKeyboardCommandTrigger Hit(ISequenceUnit sequenceUnit, string stateTree = KeyStateTrees.Default)
        {
            var combination = sequenceUnit.ToCombination();
            var trigger     = new KeyboardCommandTrigger();
            var token       = Hit(combination,
                                  trigger.OnExecute, trigger.OnCanExecute, "", stateTree) as KeyTokens;

            trigger._metaKey = token?.metaKey;
            return(trigger);
        }
        public static IKey  AllUp(this ISequenceUnit sequenceUnit, Action <IKeyEventArgs> execute,
                                  Predicate <IKeyEventArgs> canExecute = null, string description = "", string stateTree = KeyStateTrees.Default)
        {
            if (sequenceUnit is Key)
            {
                throw new Exception("AllUp event could only be used on Key, please use Up event!");
            }
            var combination      = sequenceUnit.ToCombination();
            var trigger          = Keyboard.AllUp(combination, stateTree);
            var token            = CommandManager.Add(trigger, execute, canExecute, description);
            var keyboardInternal = (IKeyboardInternal)Keyboard;

            return(keyboardInternal.GetToken(token, trigger));
        }
        private IKeyboardCommandTrigger Event(ISequenceUnit sequenceUnit, KeyEvent keyEvent,
                                              string stateTree = KeyStateTrees.Default)
        {
            var combination = sequenceUnit.ToCombination();
            var trigger     = new KeyboardCommandTrigger();
            var metaKey     = Add(combination, keyEvent,
                                  new KeyCommand(trigger.OnExecute)
            {
                CanExecute = trigger.OnCanExecute
            }, stateTree) as MetaKey;

            trigger._metaKey = metaKey;
            return(trigger);
        }
 public static ICombination Handled(this ISequenceUnit sequenceUnit,
                                    KeyEvent keyEvent = KeyEvent.Down | KeyEvent.Up | KeyEvent.AllUp)
 {
     if ((keyEvent & KeyEvent.Down) == KeyEvent.Down)
     {
         sequenceUnit.Down(e => e.Handled = true);
     }
     if ((keyEvent & KeyEvent.Up) == KeyEvent.Up)
     {
         sequenceUnit.Up(e => e.Handled = true);
     }
     if ((keyEvent & KeyEvent.AllUp) == KeyEvent.AllUp)
     {
         sequenceUnit.AllUp(e => e.Handled = true);
     }
     return(sequenceUnit.ToCombination());
 }
 public ISequence Then(ISequenceUnit sequencable)
 {
     this.Append(sequencable.ToCombination());
     return(this);
 }
 public static IKey  Map(this ISequenceUnit key, ICombination target,
                         Predicate <IKeyEventArgs> canExecute = null, int repeat = 1)
 {
     return(Keyboard.Map(key.ToCombination(), target, canExecute, repeat));
 }
 public static IKey  MapOnHit(this ISequenceUnit key, ICombination target,
                              Predicate <IKeyEventArgs> canExecute = null, bool allUp = true)
 {
     return(Keyboard.MapOnHit(key.ToCombination(), target, canExecute, allUp));
 }
 public static IKey HardMap(this ISequenceUnit key, Key target, Predicate <IKeyEventArgs> canExecute = null)
 {
     return(Keyboard.HardMap(key.ToCombination(), new Combination(target), canExecute));
 }
Exemple #12
0
 public Combination(Key triggerKey, ISequenceUnit sequenceUnit) : this(triggerKey, sequenceUnit.ToCombination().AllKeys)
 {
 }
 public ISequence Then(ISequenceUnit sequencable)
 {
     return(new Sequence(this, sequencable.ToCombination()));
 }