Skip to content

Commit 8f3b7cb

Browse files
committed
first commit
0 parents  commit 8f3b7cb

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
HELP.md
2+
target/
3+
bin/
4+
!.mvn/wrapper/maven-wrapper.jar
5+
!**/src/main/**/target/
6+
!**/src/test/**/target/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
17+
### IntelliJ IDEA ###
18+
.idea
19+
*.iws
20+
*.iml
21+
*.ipr
22+
23+
### NetBeans ###
24+
/nbproject/private/
25+
/nbbuild/
26+
/dist/
27+
/nbdist/
28+
/.nb-gradle/
29+
build/
30+
!**/src/main/**/build/
31+
!**/src/test/**/build/
32+
33+
### VS Code ###
34+
.vscode/

src/com/test/Main.java

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.test;
2+
3+
import java.util.InputMismatchException;
4+
import java.util.Scanner;
5+
6+
public class Main {
7+
8+
public static void main(String[] args) {
9+
MyThread t = null;
10+
int option = 0;
11+
String guide = "|| Please insert option number";
12+
String select1 = "| 1:start(120s)";
13+
String select2 = "| 2:start with custom duration";
14+
String select3 = "| 3:pause the script";
15+
String select4 = "| 4:stop and terminate";
16+
guide = rightPadding(guide, 70, ' ') + "||\n";
17+
select1 = rightPadding(select1, 70, ' ') + "||\n";
18+
select2 = rightPadding(select2, 70, ' ') + "||\n";
19+
select3 = rightPadding(select3, 70, ' ') + "||\n";
20+
select4 = rightPadding(select4, 70, ' ');
21+
22+
while (true) {
23+
System.out.println("=========================Mouse Auto Move Script=========================");
24+
System.out.println(guide + select1 + select2 + select3 + select4);
25+
System.out.println("========================================================================");
26+
Scanner input = new Scanner(System.in);
27+
try {
28+
option = input.nextInt();
29+
} catch (InputMismatchException e) {
30+
option = 999;
31+
}
32+
if (option == 1) {
33+
for (int i = 0; i < 50; i++) {
34+
System.out.println("\n");
35+
}
36+
System.out.println("=========================Script Started=========================");
37+
if (t != null) {
38+
t.interrupt();
39+
}
40+
t = new MyThread();
41+
t.start();
42+
} else if (option == 2) {
43+
for (int i = 0; i < 50; i++) {
44+
System.out.println("\n");
45+
}
46+
System.out.println("===============Input the detect duration(second)=================");
47+
if (t != null) {
48+
t.interrupt();
49+
}
50+
Long time = input.nextLong();
51+
t = new MyThread(time);
52+
t.start();
53+
} else if (option == 3) {
54+
for (int i = 0; i < 50; i++) {
55+
System.out.println("\n");
56+
}
57+
if (t == null) {
58+
System.out.println("*********You have to start task first for use pause function");
59+
} else {
60+
System.out.println("========================Script Paused=========================");
61+
t.interrupt();
62+
t = null;
63+
}
64+
65+
} else if (option == 4) {
66+
if (t != null) {
67+
t.interrupt();
68+
}
69+
t = null;
70+
input.close();
71+
System.out.println("=========================application terminated=========================");
72+
break;
73+
} else if (option == 999) {
74+
System.out.println(
75+
"********************Your Input type error********************\n********************Please type number in.********************");
76+
77+
} else {
78+
System.out.println("********************Please use the numbers on the menu********************");
79+
}
80+
}
81+
82+
}
83+
84+
private static String rightPadding(String str, int length, char padChar) {
85+
if (str == null) {
86+
str = "";
87+
}
88+
if (str.length() > length) {
89+
return str;
90+
}
91+
String pattern = "%-" + length + "s";
92+
return String.format(pattern, str).replace(' ', padChar);
93+
}
94+
95+
}

src/com/test/MyThread.java

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.test;
2+
3+
import java.awt.AWTException;
4+
import java.awt.MouseInfo;
5+
import java.awt.Robot;
6+
7+
public class MyThread extends Thread {
8+
Long time = null;
9+
10+
public MyThread() {
11+
super();
12+
}
13+
14+
public MyThread(Long time) {
15+
super();
16+
this.time = time;
17+
}
18+
19+
@Override
20+
public void run() {
21+
Robot robot = null;
22+
try {
23+
robot = new Robot();
24+
} catch (AWTException e1) {
25+
// TODO Auto-generated catch block
26+
e1.printStackTrace();
27+
}
28+
long times = 0L;
29+
int x = MouseInfo.getPointerInfo().getLocation().x;
30+
int y = MouseInfo.getPointerInfo().getLocation().y;
31+
while (true) {
32+
int x1 = MouseInfo.getPointerInfo().getLocation().x;
33+
int y1 = MouseInfo.getPointerInfo().getLocation().y;
34+
if (x == x1 && y == y1) {
35+
robot.mouseMove((int) Math.round(Math.random() * 100 + 0.1D),
36+
(int) Math.round(Math.random() * 100 + 0.1D));
37+
x1 = MouseInfo.getPointerInfo().getLocation().x;
38+
y1 = MouseInfo.getPointerInfo().getLocation().y;
39+
System.out.println(++times);
40+
} else {
41+
System.out.println(++times + "(moved)");
42+
}
43+
x = x1;
44+
y = y1;
45+
try {
46+
Thread.sleep(time == null ? 120000L : time * 1000);
47+
} catch (InterruptedException e) {
48+
break;
49+
}
50+
}
51+
52+
}
53+
54+
}

0 commit comments

Comments
 (0)