!752 static int viewSize = 21; static int interval = 100; static float speed = 0.3f; static float minOffset = 0f; // 0.5f; // offset needed to move at all volatile sbool useDarkCentroid = false; static JCheckBox cbDark; p { awt { showControls(jcenteredLine( cbDark = jCheckBox("Focus on dark things", useDarkCentroid, r { useDarkCentroid = cbDark.isSelected(); }) )); } new MouseMover mover; mover.endAfterInterference = false; mover.blockTimeAfterInterference = 1000; mover.enable(); while licensed { sleep(interval); if (mover.blocked()) continue; Point p = mouseLocation(); Rect area = new Rect(p.x-viewSize/2, p.y-viewSize/2, viewSize, viewSize); BWImage img = shootScreenBW(area); Pair c = bwCentroid(img, useDarkCentroid); ImageSurface is = quickShowZoomedImage(img.toRGB(), 4); float cx = c.a-viewSize/2, cy = c.b-viewSize/2; //Pt p2 = new Pt(iround(p.x+cx*speed), iround(p.y+cy*speed)); Pt p2 = new Pt(p.x+signWithThreshold(cx, minOffset), p.y+signWithThreshold(cy, minOffset)); print("Moving mouse " + (p2.x-p.x) + "/" + (p2.y-p.y) + " (centroid: " + formatDouble(cx, 2) + "/" + formatDouble(cy, 2) +")"); mover.moveMouseImmediate(p2); } mover.disable(); }