forked from manalbctt/remoteDesktopServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendEvents.java
92 lines (79 loc) · 2.32 KB
/
SendEvents.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
import javax.swing.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
public class SendEvents implements KeyListener, MouseListener, MouseMotionListener {
private Socket cSocket = null;
private JPanel cPanel = null;
private PrintWriter writer = null;
String width = "", height = "";
double w;
double h;
public SendEvents(Socket s, JPanel p, String width, String height) {
cSocket = s;
cPanel = p;
this.width = width;
this.height = height;
w = Double.parseDouble(width.trim());
h = Double.parseDouble(height.trim());
cPanel.addKeyListener(this);
cPanel.addMouseListener(this);
cPanel.addMouseMotionListener(this);
try {
writer = new PrintWriter(cSocket.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void mouseDragged(MouseEvent e) {
}
@Override
public void mouseMoved(MouseEvent e) {
double xScale = (double) w / cPanel.getWidth();
double yScale = (double) h / cPanel.getHeight();
writer.println(Commands.MOVE_MOUSE.getAbbrev());
writer.println((int) (e.getX() * xScale));
writer.println((int) (e.getY() * yScale));
writer.flush();
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
writer.println(Commands.RELEASE_MOUSE.getAbbrev());
int button = e.getButton();
int xButton = 16;
if (button == MouseEvent.BUTTON3) {
xButton = 4;
}
writer.println(xButton);
writer.flush();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
writer.println(Commands.PRESS_KEY.getAbbrev());
writer.println(e.getKeyCode());
writer.flush();
}
@Override
public void keyReleased(KeyEvent e) {
writer.println(Commands.RELEASE_KEY.getAbbrev());
writer.println(e.getKeyCode());
writer.flush();
}
}