-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmousePos.pde
67 lines (52 loc) · 1.18 KB
/
mousePos.pde
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
//Reads mouse position using robot, then puts it in Point "p"
class MousePos extends SensorReading {
//Mouse tracking:
Robot robot;
// temp stuff
// final values
int x, y;
public MousePos() {
super("mousePos");
}
void init() {
//Mouse tracking:
try {
robot = new Robot();
robot.setAutoDelay(0);
}
catch (Exception e) {
e.printStackTrace();
}
}
void execute() {
println(name + " execute");
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
Point p = pointerInfo.getLocation();
x = p.x;
y = p.y;
// for test, just get the pos and send it
send();
}
OscMessage createMessage(String adrPattern) {
OscMessage m = new OscMessage(adrPattern);
m.add(name);
m.add(x);
m.add(y);
return m;
}
void send() {
OscMessage m = createMessage("/data");
oscP5.send(m, serverLocation);
// this is important
readingDone = true;
}
SensorReading createFromMessage(OscMessage msg) {
MousePos sr = new MousePos();
sr.x = msg.get(1).intValue();
sr.y = msg.get(2).intValue();
return sr;
}
void print() {
println(name + " x: "+x+" y: "+y);
}
}