示例#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));
        }
示例#4
0
        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));
        }
示例#6
0
        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());
 }
示例#8
0
 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));
 }
示例#10
0
 public static IKey  MapOnHit(this ISequenceUnit key, ICombination target,
                              Predicate <IKeyEventArgs> canExecute = null, bool allUp = true)
 {
     return(Keyboard.MapOnHit(key.ToCombination(), target, canExecute, allUp));
 }
示例#11
0
 public static IKey HardMap(this ISequenceUnit key, Key target, Predicate <IKeyEventArgs> canExecute = null)
 {
     return(Keyboard.HardMap(key.ToCombination(), new Combination(target), canExecute));
 }
示例#12
0
 public Combination(Key triggerKey, ISequenceUnit sequenceUnit) : this(triggerKey, sequenceUnit.ToCombination().AllKeys)
 {
 }
 public ISequence Then(ISequenceUnit sequencable)
 {
     return(new Sequence(this, sequencable.ToCombination()));
 }