-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouseKeyClient.java
105 lines (97 loc) · 3.24 KB
/
MouseKeyClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.company;
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
public class MouseKeyClient {
MousePosition pos;
MouseClick click;
MouseScroll scroll;
Robot mouse;
public MouseKeyClient(int port, String host){
pos = new MousePosition(port, host);
click = new MouseClick(port, host);
scroll = new MouseScroll(port, host);
pos.start();
click.start();
scroll.start();
}
public class MousePosition extends Thread {
Socket a;
ObjectInputStream in;
public MousePosition(int port, String host){
try {
a = new Socket(host,port + 1);
in = new ObjectInputStream(a.getInputStream());
} catch (IOException E){
System.out.println(E + "MouseScroll");
}
}
public void run() {
while(true) {
try {
Point a = (Point) in.readObject();
mouse.mouseMove(a.x,a.y);
} catch (IOException | ClassNotFoundException E) {
System.out.println(E);
}
}
}
}
public class MouseClick extends Thread {
String currentMove;
Socket b;
ObjectInputStream in;
public MouseClick(int port, String host){
try {
b = new Socket(host, port + 2);
in = new ObjectInputStream(b.getInputStream());
} catch (IOException E){
System.out.println(E + "MouseClick");
}
}
public void run() {
int button = 0;
while(true){
try {
currentMove = (String) in.readObject();
button = currentMove.charAt(0);
currentMove = currentMove.replaceFirst("" + button, "");
switch (currentMove){
case "Click": mouse.mousePress(button);
mouse.delay(5);
mouse.mouseRelease(button);
break;
case "Press": mouse.mousePress(button);
break;
case "Release": mouse.mouseRelease(button);
break;
}
} catch (IOException | ClassNotFoundException E){
System.out.println(E);
}
}
}
}
public class MouseScroll extends Thread {
Socket c;
ObjectInputStream in;
public MouseScroll(int port, String host){
try {
c = new Socket(host,port + 3);
in = new ObjectInputStream(c.getInputStream());
} catch (IOException E){
System.out.println(E + "MouseScroll");
}
}
public void run(){
while(true){
try {
mouse.mouseWheel(in.read());
} catch (IOException E){
System.out.println(E);
}
}
}
}
}