-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardClient.java
45 lines (42 loc) · 1.46 KB
/
KeyboardClient.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
package com.company;
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
public class KeyboardClient extends Thread {
Socket keyboard;
ObjectInputStream in;
Robot keybard;
public KeyboardClient(int port, String host){
try {
keyboard = new Socket(host, port + 6);
in = new ObjectInputStream(keyboard.getInputStream());
keybard = new Robot();
}catch (IOException | AWTException E){
System.out.println(E);
}
}
@Override
public void run() {
while (true){
try {
String i = (String)in.readObject();
switch (i.charAt(0)){
case '1' : i = i.replaceFirst("1", "");
keybard.keyPress(Integer.parseInt(i));
keybard.delay(5);
keybard.keyRelease(Integer.parseInt(i));
break;
case '2' : i = i.replaceFirst("2", "");
keybard.keyPress(Integer.parseInt(i));
break;
case '3' : i = i.replaceFirst("3", "");
keybard.keyRelease(Integer.parseInt(i));
break;
}
} catch (IOException | ClassNotFoundException E){
System.out.println(E);
}
}
}
}