From b604c8a70d7171f51a154147c0f0062aa358f2ec Mon Sep 17 00:00:00 2001 From: davpapp Date: Tue, 30 Jan 2018 08:15:20 -0500 Subject: [PATCH] Added moveMouse code, but not yet working --- bin/Cursor.class | Bin 2612 -> 5291 bytes bin/CursorPath.class | Bin 3609 -> 3692 bytes bin/CursorTest.class | Bin 0 -> 1839 bytes bin/ScreenshotAutomator.class | Bin 0 -> 2640 bytes bin/main.class | Bin 616 -> 612 bytes src/Cursor.java | 59 +++++++++++++++++++++++++++++++--- src/CursorPath.java | 12 ++++--- src/CursorTest.java | 41 +++++++++++++++++++++++ src/ScreenshotAutomator.java | 56 ++++++++++++++++++++++++++++++++ src/main.java | 9 ++++-- 10 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 bin/CursorTest.class create mode 100644 bin/ScreenshotAutomator.class create mode 100644 src/CursorTest.java create mode 100644 src/ScreenshotAutomator.java diff --git a/bin/Cursor.class b/bin/Cursor.class index 69bf4de52a4d94a9dca6a823e71f593853d50857..372473bcbbdee06599050c397b82875bd4ce8a98 100644 GIT binary patch literal 5291 zcmb7H33MCf5&l+|EnD6sj^iXY;ZP0|*>Pe6jw!L5!*L9zwv)!jCg}kiX>D&JYt_{{ ziJ>jDrFBVZXh{#CC-lhcD=kNZ97vm{C$IFr4|+peO7HuCl792=N-H_0@Ac_P`u9I( zzM1)E{@F*LefSiB4O&$MAq^GVCY`M9L=e_cv(GqSw4{vmSj&#R`^iT)TCJkls&1T+_CrCJXX`EL>UL&mR&N_ zpMtPOIx-O7|S+gZ!+fLFVS~I)eJ>*8A;T#>yaIS{sW2Rd$YsYAS zF5BbS6FpXn<~7DWQ{!I;9A+cT*nHm z)UeFRX6ep3_i3p2_0Nhy<8TBQYM5VekP2lKtFWYsvg10c5Y@1t&q|vElM{PQXUNzq z_SE*-2_rRZIF>y7lVNw<%4(?W^FS~#)ro)+8kUqEn#$x4uAIvgoxT`9&JkQht}39V zMnuu-p>5Mq4P74FbzF+)kq$;O$?zBZ-eY}7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!iw#GWkMX dv>Pk*Y|LDPQn?0&P-zWv(;p&mfkG+x@;_(fHZlMJ delta 1611 zcmZuxTTok76kX@$CO0OB6i7pOq)etm8AyYvEv;ihTUw+NAwWx|P_*?zB7}wz!=)Ch z;!8{w|iA1JjIy2WXo1K}?_D?6%#?190cA1I$Ee*B^c57%8y2WeR zgT3OkrG8$+J_ctA{T{TVgX2Ls7}zPfJHYXfxto)_D96Kcry9wrgo6%xILZ)Xur)=a z(dI!1>d?p0kAn;rJsxN9H1$mCC-qQDPmhQCMkf6^HSNaH?Ar=a>kq zzQBgD^~mKz7|I3=ee6U`&m7iAQ*njh!Tag3pAJYf(oYb4X-C6AHp zF^)JA;x{#FufsUU1d`%!rM}*Q6PVJFVsNd87t@Uijx?r4w{@q@;FzWG&RDnDp5iz~ zaE0L09H$BXYW=4EMZB!xC5G~Kg@L&lBQeGC3eJd2Hh=I{25*Vg$Wny+XOpRTB5TL% zl;b7`7VxG_;#u*Rt=7JPw>TDYUbwYDxnNL&e#v-O9=<1H+V+YMD6`G^(+eCQ;v=!B zHAFtaXBs|baGSR!r$ha86(uE`&?%gYILn}AFg+-dZFBg2UZPCLmmB*X9Q>zK1a=_5ehu8 zisST&Um>z$Mk+4_{Nj)!xcxYpM^-Uj+VI55nM?y|=D z=v{5kLn_Id-J<4}nVyw3qbZ3kV^8qE8R@x(7uK*aT>086-jJop;auh0IlLo_A@Tcp z+(kHtr5rvcS95NDDtPX#{G426FG%{AL?;|5(pStR%HgV_NdRJ$>|PqE82aeP*T6v$ da(Npsn^lyVs*tnbgoS1yKLud|%VbdS)xRT3Fg5@H diff --git a/bin/CursorTest.class b/bin/CursorTest.class new file mode 100644 index 0000000000000000000000000000000000000000..9336681b035046ab08b0964d7f363d5884dac457 GIT binary patch literal 1839 zcmZ`(T~ixn6n>U`Y*@B|QYeJBH2sn!EyS;?1C-CSLJc26Oa(ue@D>)rZrp5Ibo3WE zUfUVR>)v>yBcUTRdhcKG4|u0nopGE|pZDDiffi?H_dV~~v(Gut+2_2!{`1q%0B)k9 zqeX);UGu80R}fWSM_5D0mi55OmMv!^yRfz;O1_3@Nrh;L<%8f64W{pwg=aY>F=sm( zwA?Y5wac$YZO8VNu;RTT!qc`q{~Qg~N9`dRbIJ zz(5b;tAGT~6*0c@nSI(Smuh9p z7llpXTT{Y+D1@`<+K$gM6H7J6w|7L*uG-`<={T-$sme5*&%546cB{t9`K;K!@Um9L z&MHa<)1*wCL7R?@hWH@`g=`>=8?tYM8X~FL*>q7d$eMT&FOdYh_WvbaN#&1&jXb+g z=VbO*OuUMl8ctc&s_^_-XNekMcO$7>E?ta{|8?o_LT<1(I?>uNerb64_buw?SyZ~$ zc$avu^A@d`#%&!G$`Oeze_Hj$j)^;XlR|N8R9kldWV_i#k4;_nJz?#P=$O^e)6^#2 zwzDx+v&-wkGw>GXbmWgis|XYGSkRz9u*x;DaG&t0Tsp|0G#=oL7?{D^vcXF-;`#UK zVhjZhZAr0P;Y^72;iUYeXyP8;rL3$G0(=bTk}fdjx8s?y?OWy$zqYD z5JNnjXzl6$z^#O_ojv=gO+h^LX@vze#wFwa#+ zgpTC7MtoV<3tU;c#>r9yzsS@vaDenmD7263d1-YR(wtMy4uj^r@;;T`;c(!7D(y%n z^CSAM->73KUdPM9Zjie!ymq)xgq7osrX!*p!*n!h4Y6F{EXna`L@#M2a20(#Va{O` z7jPH-Sj9zb^B;YVON#PXK%hZ64wsR)NHIZ?jnQf$!V1P|g@`kU30h&sO!B%#`j96M z_HidfP!`U9p8Ftal71b6qb*tuNCJLx)B>Uh77j|b8ue0lrPx9C)6|Mu74Ko37g zIP?TUvI!{x#JPgmFW?$R*mC)UlFB!F_=85tCC2Q`i88Gac4$Y?^7@1nmBUR7-2VXf Cuaz4B literal 0 HcmV?d00001 diff --git a/bin/ScreenshotAutomator.class b/bin/ScreenshotAutomator.class new file mode 100644 index 0000000000000000000000000000000000000000..788778da2a3f56e83fbd024e3bd2c1799ab17af6 GIT binary patch literal 2640 zcmZ`)TUQ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Yh5#ea_7kF9%uX%-i^HGz*R0E2J*EGHX@o zxUca7rBNEk5)b=Qf@Efsb{mjMcIMF&F)49iNQ#ui?}GrgNOWI6?Cd*Fd!3b9_O-2z~P<)mKLS I%BS@8zfrnkhyVZp literal 0 HcmV?d00001 diff --git a/bin/main.class b/bin/main.class index 65bca78638155adffbbb083541f0bef356038963..8af913e423e8744aad6dd778893a59f61bdd9438 100644 GIT binary patch delta 353 zcmY+9%}&BV6ot>Nl)_l6$WH|o{|&}PSFT(c;-U!)7X-tyk%_5+4rvE;$HEuT_zJ#& z8%ZSb0elV@K85ij3DL!zb7$_k-_3lbK2zf3`|TaT2@W5{!-ycx@2+HDhbl@eJD8t@h3?oAaK9JfZsA>ITuZ=SNz`@u06|=TD|cNY@8(qGEvpvKH0|&YX9l!bl6a zsMs*EPB3eyzJJu3W;bnAu|;ruYA9!jrm8Cycfu&pG9lz^jsK)4N%tcYi~JcI#A>oH zv1ehx;j_$jntcVUu()ni4*D_8DRTxC(HE?f?6Xh+hdBvT=)E_?ySC(%U( z1s}lYaN$#kC+SuOzW>bmIsb6xTm4auuiy7i0H-*9G9D)y>I~(JagxS~fg1E24GW7X zGcQFFG9gXT6sufb_1GU>XEcho=*spNx^(i)9$WUMqZK%Ww f9i2i<`j4ETor_`YVZZRJIKUxAGaS)f0c-sMPH;ux diff --git a/src/Cursor.java b/src/Cursor.java index 2e3eac3..70e4b40 100644 --- a/src/Cursor.java +++ b/src/Cursor.java @@ -1,28 +1,33 @@ /* Reads a file of coordinates */ +import java.awt.AWTException; import java.awt.MouseInfo; import java.awt.Point; import java.awt.PointerInfo; +import java.awt.Robot; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Cursor { - public static final int NUMBER_OF_DISTANCES = 600; + public static final int NUMBER_OF_DISTANCES = 1000; + private Robot robot; private ArrayList> cursorPathsByDistance; - public Cursor() { + public Cursor() throws AWTException { ArrayList cursorPaths = getArrayListOfCursorPathsFromFile("/home/dpapp/GhostMouse/coordinates.txt");// read from file or something; - initializeCursorPathsByDistance(); assignCursorPathsByDistance(cursorPaths); + + robot = new Robot(); } private void initializeCursorPathsByDistance() { @@ -49,10 +54,56 @@ public class Cursor { this.cursorPathsByDistance.get(cursorPath.getCursorPathDistance()).add(cursorPath); } + public void moveCursorToCoordinates(Point goalPoint) throws InterruptedException { + Point startingCursorPoint = getCurrentCursorPoint(); + int distanceToMoveCursor = calculateDistanceBetweenPoints(startingCursorPoint, goalPoint); + double thetaDirectionToMoveCursor = calculateThetaBetweenPoints(startingCursorPoint, goalPoint); + + CursorPath cursorPathToFollow = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor); + System.out.println("Starting from " + startingCursorPoint.x + ", " + startingCursorPoint.y); + System.out.println("Moving to " + goalPoint.x + ", " + goalPoint.y); + System.out.println("Moving in " + thetaDirectionToMoveCursor / Math.PI * 180 + " degree direction."); + followCursorPath(startingCursorPoint, thetaDirectionToMoveCursor, cursorPathToFollow); + } + + private void followCursorPath(Point startingCursorPoint, double thetaDirectionToMoveCursor, CursorPath cursorPathToFollow) throws InterruptedException { + for (CursorPoint translationPoint : cursorPathToFollow.getCursorPathPoints()) { + robotMouseMove(calculatePoint(startingCursorPoint, thetaDirectionToMoveCursor, translationPoint)); + Thread.sleep(50); + } + } + + private Point calculatePoint(Point startingCursorPoint, double thetaDirectionToMoveCursor, CursorPoint translationPoint) { + int x = (int) (startingCursorPoint.x + Math.cos(thetaDirectionToMoveCursor) * translationPoint.x); + int y = (int) (startingCursorPoint.y + Math.sin(thetaDirectionToMoveCursor) * translationPoint.y); + return new Point(x, y); + } + + private void robotMouseMove(Point pointToMoveCursorTo) { + robot.mouseMove(pointToMoveCursorTo.x, pointToMoveCursorTo.y); + } + + private CursorPath chooseCursorPathToFollowBasedOnDistance(int distanceToMoveCursor) { + ArrayList cursorPathsWithSameDistance = cursorPathsByDistance.get(distanceToMoveCursor); + return cursorPathsWithSameDistance.get(new Random().nextInt(cursorPathsWithSameDistance.size())); + } + + private int calculateDistanceBetweenPoints(Point a, Point b) { + return (int) (Math.hypot(a.x - b.x, a.y - b.y)); + } + + public double calculateThetaBetweenPoints(Point a, Point b) { + return Math.atan2((b.y - a.y), (b.x - a.x)); + } + + private Point getCurrentCursorPoint() { + return MouseInfo.getPointerInfo().getLocation(); + } + + public void displaycursorPathsByDistance() { for (int i = 0; i < cursorPathsByDistance.size(); i++) { System.out.println("There are " + cursorPathsByDistance.get(i).size() + " CursorPaths of length " + i); - } } } \ No newline at end of file diff --git a/src/CursorPath.java b/src/CursorPath.java index 4cb2c3a..81a88c1 100644 --- a/src/CursorPath.java +++ b/src/CursorPath.java @@ -13,17 +13,19 @@ public class CursorPath { public CursorPath(ArrayList cursorPoints) { - this.pathCursorPoints = deepCopyCursorPoints(cursorPoints); + this.pathCursorPoints = copyCursorPointsWithOffset(cursorPoints); this.pathNumPoints = cursorPoints.size(); this.pathDistance = calculateCursorPathDistance(); this.pathTimespanMilliseconds = calculateCursorPathTimespan(); } - private ArrayList deepCopyCursorPoints(ArrayList cursorPoints) { + private ArrayList copyCursorPointsWithOffset(ArrayList cursorPoints) { ArrayList cursorPointsCopy = new ArrayList(cursorPoints.size()); + CursorPoint startingCursorPoint = cursorPoints.get(0); for (CursorPoint cursorPoint : cursorPoints) { - CursorPoint cursorPointCopy = new CursorPoint(cursorPoint.x, cursorPoint.y, cursorPoint.time); - cursorPointsCopy.add(cursorPointCopy); + CursorPoint offsetCursorPoint = new CursorPoint(cursorPoint.x - startingCursorPoint.x, + cursorPoint.y - startingCursorPoint.y,cursorPoint.time - startingCursorPoint.time); + cursorPointsCopy.add(offsetCursorPoint); } return cursorPointsCopy; } @@ -58,7 +60,7 @@ public class CursorPath { } private boolean isCursorPathDistanceReasonable() { - return (this.pathDistance > 5 && this.pathDistance < 600); + return (this.pathDistance > 5 && this.pathDistance < 1000); } private boolean isCursorPathNumPointsReasonable() { diff --git a/src/CursorTest.java b/src/CursorTest.java new file mode 100644 index 0000000..47b4454 --- /dev/null +++ b/src/CursorTest.java @@ -0,0 +1,41 @@ +import static org.junit.jupiter.api.Assertions.*; + +import java.awt.AWTException; +import java.awt.Point; + +import org.junit.jupiter.api.Test; + +class CursorTest { + + Cursor cursor; + double toleranceMin; + double toleranceMax; + + void initialize() throws AWTException { + cursor = new Cursor(); + toleranceMin = 0.9999; + toleranceMax = 1.0001; + } + + @Test + void testCalculateThetaBetweenPoints() throws AWTException { + initialize(); + Point a = new Point(0, 0); + Point b = new Point(10, 0); + Point c = new Point(0, 10); + Point d = new Point(-10, 0); + Point e = new Point(0, -10); + + assertInRange(cursor.calculateThetaBetweenPoints(a, b), 0.0); + assertInRange(cursor.calculateThetaBetweenPoints(a, c), Math.PI / 2); + assertInRange(cursor.calculateThetaBetweenPoints(a, d), Math.PI); + assertInRange(cursor.calculateThetaBetweenPoints(a, e), - Math.PI / 2); + } + + void assertInRange(double valueToTest, double expectation) { + System.out.println(valueToTest + " expected: " + expectation); + assertTrue((valueToTest <= (expectation * toleranceMax)) && (valueToTest >= (expectation * toleranceMin))); + } + +} + \ No newline at end of file diff --git a/src/ScreenshotAutomator.java b/src/ScreenshotAutomator.java new file mode 100644 index 0000000..0b57af4 --- /dev/null +++ b/src/ScreenshotAutomator.java @@ -0,0 +1,56 @@ +import java.awt.AWTException; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +import javax.imageio.ImageIO; + +public class ScreenshotAutomator { + + public String screenshotOutputDirectory; + public Robot robot; + public Rectangle screenAreaToCapture; + + public ScreenshotAutomator(String screenshotOutputDirectory) throws AWTException { + this.screenshotOutputDirectory = screenshotOutputDirectory; + this.screenAreaToCapture = new Rectangle(0, 0, 1920 / 2, 1080); + this.robot = new Robot(); + } + + public void captureEveryNSeconds(int n) throws IOException, InterruptedException { + for (int i = 0; i < 20; i++) { + captureScreenshot(i); + System.out.println("Created image: " + getImageName(i)); + Thread.sleep(n * 1000); + } + } + + public void captureOnKeyboardInput() throws IOException, InterruptedException { + int counter = 0; + Scanner scanner = new Scanner(System.in); + while (true) { + captureScreenshot(counter); + scanner.nextLine(); + System.out.println("Created image: " + getImageName(counter)); + counter++; + } + } + + private void captureScreenshot(int counter) throws IOException { + BufferedImage image = robot.createScreenCapture(this.screenAreaToCapture); + ImageIO.write(image, "png", new File(getImageName(counter))); + } + + private String getImageName(int counter) { + return screenshotOutputDirectory + "screenshot" + counter + ".png"; + } + + public static void main(String[] args) throws Exception + { + ScreenshotAutomator screenshotAutomator = new ScreenshotAutomator("/home/dpapp/Desktop/RunescapeAIPics/"); + screenshotAutomator.captureOnKeyboardInput(); + } +} diff --git a/src/main.java b/src/main.java index f3749e9..a664f88 100644 --- a/src/main.java +++ b/src/main.java @@ -1,13 +1,16 @@ +import java.awt.AWTException; +import java.awt.Point; import java.net.URL; public class main { - public static void main(String[] args) { + public static void main(String[] args) throws AWTException, InterruptedException { // TODO Auto-generated method stub Cursor cursor = new Cursor(); - cursor.displaycursorPathsByDistance(); + cursor.moveCursorToCoordinates(new Point(620, 420)); + //cursor.displaycursorPathsByDistance(); - System.out.println("Finished..."); + //System.out.println("Finished..."); } }