public override bool Merge(IRecordStep NextStep) { if (NextStep is ScrollStep nextStep) { // Scroll in same direction if (Math.Sign(Args.Delta) == Math.Sign(nextStep.Args.Delta)) { return(true); } } return(base.Merge(NextStep)); }
public override bool Merge(IRecordStep NextStep) { switch (NextStep) { case MouseClickStep mouseClickStep when Args.Clicks == 1: var delta = (mouseClickStep.Timestamp - Timestamp).TotalMilliseconds; if (mouseClickStep.Args.Clicks == 2 && delta < DoubleClickDelta) { Args = mouseClickStep.Args; return(true); } break; } return(base.Merge(NextStep)); }
public bool Merge(IRecordStep NextStep) { if (NextStep is KeyStep nextStep) { if (_repeat == 0 && _mergeable && nextStep.Text.Length == 1) { Text += nextStep.Text; return(true); } if (Text == nextStep.Text) { ++_repeat; return(true); } } return(false); }
public virtual bool Merge(IRecordStep NextStep) { switch (NextStep) { case KeyStep keyStep: if (_modifierStates.Control && keyStep.Text == _keymap.Control) { return(true); } if (_modifierStates.Shift && keyStep.Text == _keymap.Shift) { return(true); } if (_modifierStates.Alt && keyStep.Text == _keymap.Alt) { return(true); } break; } return(false); }
public override bool Merge(IRecordStep NextStep) { if (NextStep is MouseDragStep mouseDragStep) { mouseDragStep.StartPoint = _start; _end = mouseDragStep.EndPoint; var diffX = (_end.X - _start.X); var diffY = (_end.Y - _start.Y); var mag = Math.Sqrt(diffX * diffX + diffY * diffY); _end = new Point((int)(_start.X + diffX * DragBeginLength / mag), (int)(_start.Y + diffY * DragBeginLength / mag)); return(false); } else if (NextStep is MouseClickStep) { return(true); } return(base.Merge(NextStep)); }
IObservable <IRecordStep> Observe(IMouseKeyHook Hook, CancellationToken CancellationToken, out IObservable <Unit> ShotObservable) { var subject = new Subject <IRecordStep>(); var shotSubject = new Subject <Unit>(); ShotObservable = shotSubject; void OnNext(IRecordStep NextStep) { if (_lastStep != null) { if (_lastStep.Merge(NextStep)) { return; } subject.OnNext(_lastStep); } shotSubject.OnNext(Unit.Default); _lastStep = NextStep; } Hook.MouseClick += (S, E) => { var step = new MouseClickStep(_mouseClickSettings, _keystrokesSettings, E, _keymap); OnNext(step); }; Hook.MouseDoubleClick += (S, E) => { var step = new MouseClickStep(_mouseClickSettings, _keystrokesSettings, E, _keymap); OnNext(step); }; Hook.MouseDragStarted += (S, E) => { var step = new MouseDragBeginStep(E.Location, _mouseClickSettings, _keystrokesSettings, _keymap); OnNext(step); }; Hook.MouseDragFinished += (S, E) => { var step = new MouseDragStep(E.Location, _mouseClickSettings, _keystrokesSettings, _keymap); OnNext(step); }; if (_stepsSettings.IncludeScrolls) { // TODO: Event is not firing for touchpad scroll Hook.MouseWheel += (S, E) => { var step = new ScrollStep(E, _mouseClickSettings, _keystrokesSettings, _keymap); OnNext(step); }; } Hook.KeyDown += (S, E) => { _modifierSingleDown = false; var record = new KeyRecord(E, _keymap); var display = record.Display; if (display == _keymap.Control || display == _keymap.Alt || display == _keymap.Shift) { _modifierSingleDown = true; } else { OnNext(new KeyStep(_keystrokesSettings, record)); } }; Hook.KeyUp += (S, E) => { var record = new KeyRecord(E, _keymap); var display = record.Display; if (display == _keymap.Control || display == _keymap.Alt || display == _keymap.Shift) { if (_modifierSingleDown) { OnNext(new KeyStep(_keystrokesSettings, record)); } } }; CancellationToken.Register(() => { shotSubject.OnCompleted(); subject.OnNext(_lastStep); subject.OnCompleted(); }); return(subject .Where(M => _recording)); }