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); } MouseDownAction action = (MouseDownAction)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.MouseDownAction) { MouseDownAction m_action = (MouseDownAction)action; if (m_action._button == this._button) { if (this._x <= (int)(m_action._x + MAX_X_OFFSET) && this._x >= (int)(m_action._x - MAX_X_OFFSET) && this._y <= (int)(m_action._y + MAX_Y_OFFSET) && this._y >= (int)(m_action._y - MAX_Y_OFFSET)) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } }
public override UserAction Merge(UserAction action) { UserAction ret = null; if (action != null && action.ActionType == UserActionType.MouseDownAction) { MouseDownAction m_action = (MouseDownAction)action; if (this.Button == m_action.Button) { if (this.Window.Handle == m_action.Window.Handle && this.Modifiers == m_action.Modifiers && this.X <= m_action.X + MAX_X_OFFSET && this.X >= m_action.X - MAX_X_OFFSET && this.Y <= m_action.Y + MAX_Y_OFFSET && this.Y >= m_action.Y - MAX_Y_OFFSET) { ret = new MouseClickAction(m_action.Window, m_action.Button, m_action.X, m_action.Y, m_action.Modifiers); } else { ret = new MouseDragAction(m_action.Window, m_action.Button, m_action.X, m_action.Y, this.X, this.Y, m_action.Modifiers); } ret.Time = this._time; } } return(ret); }
public override object Clone() { MouseDownAction action = new MouseDownAction(new Window(_window), _button, _x, _y, _modifiers); action.Id = this.Id; action.Time = this.Time; return(action); }
public override bool Equals(UserAction action) { if ((object)action == null) { 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.MouseDownAction) { MouseDownAction m_action = (MouseDownAction)action; if (m_action._button == this._button) { if (this._x <= (int)(m_action._x + MAX_X_OFFSET) && this._x >= (int)(m_action._x - MAX_X_OFFSET) && this._y <= (int)(m_action._y + MAX_Y_OFFSET) && this._y >= (int)(m_action._y - MAX_Y_OFFSET)) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } }
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; }