Ejemplo n.º 1
0
        public IKey HardMap(ICombination source, ICombination target,
                            Predicate <IKeyEventArgs> predicate = null)
        {
            var handled = false;

            return(new KeyTokens()
            {
                source.Down(e =>
                {
                    handled = true;
                    e.Handled = true;
                    e.NoFurtherProcess = true;

                    InputSimu.Inst.Keyboard.ModifiedKeyDown(
                        target.Chord.Cast <VirtualKeyCode>(),
                        (VirtualKeyCode)(Keys)target.TriggerKey);
                }, predicate, "", KeyStateTrees.HardMap),
                source.Up(e =>
                {
                    handled = false;

                    e.Handled = true;
                    e.NoFurtherProcess = true;

                    InputSimu.Inst.Keyboard.ModifiedKeyUp(target.Chord.Cast <VirtualKeyCode>(),
                                                          (VirtualKeyCode)(Keys)target.TriggerKey);
                }, e =>
                {
                    if (!handled)
                    {
                        Console.WriteLine("\t/!Handling:false");
                        return false;
                    }

                    if (predicate != null && !predicate(e))
                    {
                        Console.WriteLine("\t/!predicate(e):false");
                        return false;
                    }

                    return true;
                }, "", KeyStateTrees.HardMap)
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// down up happened successively
        /// </summary>
        internal IKey Hit(ICombination combination, Action <IKeyEventArgs> execute,
                          Predicate <IKeyEventArgs> canExecute = null, string description = "", string stateTree = KeyStateTrees.Default)
        {
            var           handling     = false;
            IKeyEventArgs keyDownEvent = null;
            var           token        = new KeyTokens
            {
                combination.Down(e =>
                {
                    handling     = true;
                    keyDownEvent = e;
                }, canExecute, description, stateTree),

                combination.Up(e =>
                {
                    if (!handling)
                    {
                        Console.WriteLine($"\t{combination}_Hit Down CanExecute:false");
                        return;
                    }

                    handling = false;

                    if (keyDownEvent == e.LastKeyDownEvent)
                    {
                        e.BeginInvoke(() => execute(e));
                    }
                    else
                    {
                        Console.WriteLine($"\t{combination}_Hit: last down event is not from me, Not Execute!");
                    }
                }, canExecute, description, stateTree)
            };

            return(token);
        }