private Boolean closeCursors(cursorInTime c1, cursorInTime c2) { // Check that X and Y positions of cursor 1 are not more than CURSOR_DISTANCE away if (Math.Abs(c1.p.X - c2.p.X) < this.parameters.clickValues.clickBoundingBox && Math.Abs(c1.p.Y - c2.p.Y) < this.parameters.clickValues.clickBoundingBox) { return(true); } return(false); }
public ClickDetector(ClickStatus status, CursorCapture capture, CustomizationParameters parameters, MainForm form) { this.status = status; this.capture = capture; this.parameters = parameters; this.form = form; this.lastClick = new cursorInTime(-50, -50, null); InitTimer(); this.automator = new CUIAutomation(); }
public ClickDetector(ClickStatus status, CursorCapture capture, CustomizationParameters parameters, MainForm form) { this.status = status; this.capture = capture; this.parameters = parameters; this.form = form; this.lastClick = new cursorInTime(-50, -50, null); InitTimer(); this.automator = new CUIAutomation(); this.lastSentToBack = 0; }
// This is called every timer1.Interval private void timer1_Tick(object sender, EventArgs e) { // Take snapshot of current cursor cursorInTime cursor = CursorCapture.CaptureCursor(); if (cursor == null) { cursor.cursor.Dispose(); return; } if (this.parameters.layoutValues.autoHide) { // Magic Number for hiding (fix this) if (this.lastSentToBack >= 50) { if (Win32Stuff.GetForegroundWindow() == this.form.Handle) { if (!this.form.Bounds.Contains(cursor.p) && !this.form.fetcher.Bounds.Contains(cursor.p)) { this.lastSentToBack = 0; this.form.SendToBack(); this.form.Hide(); } } } } this.lastSentToBack++; if (this.status.getCurrentMode() == null && this.status.getBackgroundMode() == ProgramMode.sleepClick) { cursor.cursor.Dispose(); return; } MouseTracker.Add(cursor); if (MouseTracker.Count >= 10) { // Check if the mouse has dwelled and proceed from there int currentCursorIndex = this.checkDwell(); if (currentCursorIndex != -1) { // There was a dwell, so we should click checkDragThenClick(currentCursorIndex); } else { // The last click position is not valid anymore, clear it this.lastClick = new cursorInTime(-50, -50, null); } } }
// Wrapper function for click() that scans last few cursors to aid click and drag in context mode private void checkDragThenClick(int currentCursorIndex) { // Check if the lastClick as close to the current one if (closeCursors(MouseTracker[currentCursorIndex], lastClick)) { // If it was, check to see if any of the other cursors have moved far enough from the first click if (MouseTracker.Any(p => !closeCursors(p, lastClick))) { // We've moved from the last click and come back, continue clicking } // Otherwise, clear this set of captures cursors - using the current last click as the last click now else { this.lastClick = MouseTracker[currentCursorIndex]; clearCursors(); return; } } if (this.parameters.contextValues.compareCursors) { int clickAndDragCursors = MouseTracker.Count(p => capture.IsClickAndDrag(p.cursor)); if (clickAndDragCursors > 1) { if (capture.IsClickAndDrag(MouseTracker[currentCursorIndex].cursor)) { click(MouseTracker[currentCursorIndex].p, true); Debug.Print("Click and drag cursor click!"); lastClick = MouseTracker[currentCursorIndex]; clearCursors(); return; } else { // This didn't work - Programs freak out when you click where the mouse isn't // TODO: See if there is any way to get the mouse not to freak out when moved // This section would move the cursor back to a resize position if some of the cursors matched, // to help with efficiency //cursorInTime lastDrag = MouseTracker.Last(p => capture.IsClickAndDrag(p.cursor)); //SetCursorPos(lastDrag.p.X, lastDrag.p.Y); //click(lastDrag.p, true); } } } click(MouseTracker[currentCursorIndex].p, false); lastClick = MouseTracker[currentCursorIndex]; clearCursors(); }
// Wrapper function for click() that scans last few cursors to aid click and drag in context mode private void checkDragThenClick(int currentCursorIndex) { // Check if the lastClick as close to the current one if (closeCursors(MouseTracker[currentCursorIndex], lastClick)) { // If it was, check to see if any of the other cursors have moved far enough from the first click if (MouseTracker.Any(p => !closeCursors(p, lastClick))) { // We've moved from the last click and come back, continue clicking } // Otherwise, clear this set of captures cursors - using the current last click as the last click now else { this.lastClick = MouseTracker[currentCursorIndex]; MouseTracker.Clear(); return; } } if (this.parameters.contextValues.compareCursors) { int clickAndDragCursors = MouseTracker.Count(p => capture.IsClickAndDrag(p.cursor)); if (clickAndDragCursors > 1) { if (capture.IsClickAndDrag(MouseTracker[currentCursorIndex].cursor)) { click(MouseTracker[currentCursorIndex].p, true); lastClick = MouseTracker[currentCursorIndex]; MouseTracker.Clear(); return; } else { // This didn't work - Programs freak out when you click where the mouse isn't // TODO: See if there is any way to get the mouse not to freak out when moved //cursorInTime lastDrag = MouseTracker.Last(p => capture.IsClickAndDrag(p.cursor)); //SetCursorPos(lastDrag.p.X, lastDrag.p.Y); //click(lastDrag.p, true); } } } click(MouseTracker[currentCursorIndex].p, false); lastClick = MouseTracker[currentCursorIndex]; MouseTracker.Clear(); }
// This is called every timer1.Interval private void timer1_Tick(object sender, EventArgs e) { // Take snapshot of current cursor cursorInTime cursor = CursorCapture.CaptureCursor(); if (cursor == null) { return; } MouseTracker.Add(cursor); if (MouseTracker.Count >= 10) { // Check if the mouse has dwelled and proceed from there int currentCursorIndex = this.checkDwell(); if (currentCursorIndex != -1) { // There was a dwell, so we should click checkDragThenClick(currentCursorIndex); } else { // The last click position is not valid anymore, clear it this.lastClick = new cursorInTime(-50, -50, null); } } }
private Boolean closeCursors(cursorInTime c1, cursorInTime c2) { // Check that X and Y positions of cursor 1 are not more than CURSOR_DISTANCE away if (Math.Abs(c1.p.X - c2.p.X) < this.parameters.clickValues.clickBoundingBox && Math.Abs(c1.p.Y - c2.p.Y) < this.parameters.clickValues.clickBoundingBox) { return true; } return false; }