コード例 #1
0
        public override object Clone()
        {
            KeyUpAction action = new KeyUpAction(new Window(_window), _key, _modifiers);

            action.Id   = this.Id;
            action.Time = this.Time;
            return(action);
        }
コード例 #2
0
        public override bool Equals(object obj)
        {
            if (obj == null) // check if its null
            {
                return(false);
            }

            if (this.GetType() != obj.GetType()) // check if the type is the same
            {
                return(false);
            }

            KeyUpAction action = (KeyUpAction)obj;

            if (action == null) // check if it can be casted
            {
                return(false);
            }

            if (this.Id > -1 && action.Id > -1) // id already specified
            {
                if (this.Id == action.Id)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (action.ActionType == UserActionType.KeyUpAction)
                {
                    if (((KeyUpAction)action)._key == this._key)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #3
0
ファイル: UserActionWindow.cs プロジェクト: erisonliang/Blaze
        public void AddAction(UserAction action)
        {
            ValidadeActions();
            //_mutex.WaitOne();
            if (UseCompression)
            {
                // if last actions was a MouseDown but the new one isn't a MouseUp, then replace the MouseDown by a MouseClick
                if ((GetLastAction() != null && GetLastAction().ActionType == UserAction.UserActionType.MouseDownAction))
                {
                    MouseDownAction temp_action = (MouseDownAction)GetLastAction();
                    if (action.ActionType == UserAction.UserActionType.MouseUpAction)
                    {
                        UserAction merged_action = action.Merge(temp_action);
                        if (merged_action == null) // if there is no possible merging, ignore the mouse up
                        {
                            MouseClickAction click = new MouseClickAction(temp_action.Window, temp_action.Button, temp_action.X, temp_action.Y, temp_action.Modifiers);
                            click.Time = temp_action.Time;
                            ReplaceLastAction(click);
                        }
                    }
                    else
                    {
                        MouseClickAction click = new MouseClickAction(temp_action.Window, temp_action.Button, temp_action.X, temp_action.Y, temp_action.Modifiers);
                        click.Time = temp_action.Time;
                        ReplaceLastAction(click);
                    }
                    //click.Id = temp_action.Id;
                    //_user_actions[_user_actions.Count - 1] = click;
                }

                // ignore KeyUp events
                if (action.ActionType == UserAction.UserActionType.KeyUpAction)
                {
                    UserAction last_action = _last_processed_action;
                    if (last_action != null)
                    {
                        KeyUpAction key_action = (KeyUpAction)action;
                        if (key_action.Key == System.Windows.Forms.Keys.LMenu ||
                            key_action.Key == System.Windows.Forms.Keys.RMenu)
                        {
                            if ((_modifiers & UserAction.Modifiers.Alt) != UserAction.Modifiers.Alt)
                            {
                                UserAction new_action = new KeyPressAction(last_action.Window, key_action.Key, key_action.Modifiers);
                                new_action.Time = key_action.Time;
                                BasicAddAction(new_action);
                                return;
                            }
                            else
                            {
                                _modifiers &= ~UserAction.Modifiers.Alt;
                                return;
                            }
                        }
                        else if (key_action.Key == System.Windows.Forms.Keys.LControlKey ||
                                 key_action.Key == System.Windows.Forms.Keys.RControlKey)
                        {
                            if ((_modifiers & UserAction.Modifiers.Ctrl) != UserAction.Modifiers.Ctrl)
                            {
                                UserAction new_action = new KeyPressAction(last_action.Window, key_action.Key, key_action.Modifiers);
                                new_action.Time = key_action.Time;
                                BasicAddAction(new_action);
                                return;
                            }
                            else
                            {
                                _modifiers &= ~UserAction.Modifiers.Ctrl;
                                return;
                            }
                        }
                        else if (key_action.Key == System.Windows.Forms.Keys.LShiftKey ||
                                 key_action.Key == System.Windows.Forms.Keys.RShiftKey)
                        {
                            if ((_modifiers & UserAction.Modifiers.Shift) != UserAction.Modifiers.Shift)
                            {
                                UserAction new_action = new KeyPressAction(last_action.Window, key_action.Key, key_action.Modifiers);
                                new_action.Time = key_action.Time;
                                BasicAddAction(new_action);
                                return;
                            }
                            else
                            {
                                _modifiers &= ~UserAction.Modifiers.Shift;
                                return;
                            }
                        }
                        else if (key_action.Key == System.Windows.Forms.Keys.LWin ||
                                 key_action.Key == System.Windows.Forms.Keys.RWin)
                        {
                            if ((_modifiers & UserAction.Modifiers.Win) != UserAction.Modifiers.Win)
                            {
                                UserAction new_action = new KeyPressAction(last_action.Window, key_action.Key, key_action.Modifiers);
                                new_action.Time = key_action.Time;
                                BasicAddAction(new_action);
                                return;
                            }
                            else
                            {
                                _modifiers &= ~UserAction.Modifiers.Win;
                                return;
                            }
                        }
                    }
                    else
                    {
                        _last_processed_action = (UserAction)action.Clone();
                        _modifiers             = UserContext.Instance.ObserverObject.Modifiers;
                        return;
                    }
                }
                // ignore a MouseUp event if the last one isn't a MouseDown
                else if (action.ActionType == UserAction.UserActionType.MouseUpAction &&
                         (GetLastAction() == null || GetLastAction().ActionType != UserAction.UserActionType.MouseDownAction))
                {
                    _last_processed_action = action;
                    _modifiers             = UserContext.Instance.ObserverObject.Modifiers;
                    return;
                }
                // if new action is a KeyDown, replace it by a KeyPress
                else if (action.ActionType == UserAction.UserActionType.KeyDownAction)
                {
                    KeyDownAction temp_action = (KeyDownAction)action;
                    UserAction    new_action  = new KeyPressAction(temp_action.Window, temp_action.Key, temp_action.Modifiers);
                    new_action.Time = temp_action.Time;
                    //new_action.Id = temp_action.Id;
                    BasicAddAction(new_action);
                }
                else if (action.ActionType == UserAction.UserActionType.KeyPressAction)
                {
                    KeyPressAction temp_action = (KeyPressAction)action;
                    BasicAddAction(temp_action);
                }
                // otherwise, just merge the last logged action with the new one
                else
                {
                    UserAction last_action   = GetLastAction();
                    UserAction merged_action = action.Merge(last_action);
                    if (merged_action != null) // if merge was successful, replace the last action by the merged one
                    {
                        if (merged_action.IsType(UserAction.UserActionType.TerminalAction))
                        {
                            RemoveLastAction();
                        }
                        else
                        {
                            merged_action.Time = action.Time;
                            ReplaceLastAction(merged_action);
                        }
                    }
                    else // just add the new action
                    {
                        BasicAddAction(action);
                    }
                }
                // compress even more
                bool can_compress_more = true;
                while (can_compress_more)
                {
                    UserAction last_action        = GetLastAction();
                    UserAction second_last_action = GetSecondLastAction();
                    if (last_action != null && second_last_action != null)
                    {
                        UserAction merged_action = last_action.Merge(second_last_action);
                        if (merged_action != null)
                        {
                            if (merged_action.IsType(UserAction.UserActionType.TerminalAction))
                            {
                                RemoveLastAction();
                                RemoveLastAction();
                            }
                            else
                            {
                                merged_action.Time = last_action.Time;
                                RemoveLastAction();
                                //merged_action.Id = second_last_action.Id;
                                //_user_actions[_user_actions.Count - 1] = merged_action;
                                ReplaceLastAction(merged_action);
                            }
                        }
                        else
                        {
                            can_compress_more = false;
                        }
                    }
                    else
                    {
                        can_compress_more = false;
                    }
                }
            }
            else
            {
                BasicAddAction(action);
            }
            _last_processed_action = (UserAction)action.Clone();
            _modifiers             = UserContext.Instance.ObserverObject.Modifiers;
        }