-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
69 lines (50 loc) · 1.87 KB
/
__init__.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import zmq
import sys, time
import threading
import simplejson
from Xlib import X, display
import pymouse
class FreenectControlServer():
def __init__(self):
context = zmq.Context()
self.subscriber = context.socket (zmq.SUB)
self.subscriber.connect ("tcp://*:14444")
self.subscriber.setsockopt (zmq.SUBSCRIBE, "event")
d = display.Display()
s = d.screen()
root = s.root
m = pymouse.PyMouse()
width, height = m.screen_size()
last_position = { 'x':0, 'y':0 }
mouse_down = False
while True:
try:
message = self.subscriber.recv()
message = simplejson.loads(message)
except:
message = "undefined"
print message
if type(message).__name__=='str':
pass
elif message['type'] == "Unregister":
mouse_down = False
elif message['type'] == "HandClick":
message['data'] = last_position
x = width / 100 * (100 - int(message['data']['x']))
y = height / 100 * int(message['data']['y'])
if mouse_down:
m.release(x, y)
else:
m.press(x, y)
mouse_down = not mouse_down
elif message['type'] == "Move":
x = width / 100 * (100 - int(message['data']['x']))
y = height / 100 * int(message['data']['y'])
#root.warp_pointer(x,y)
#d.sync()
last_position = message['data']
m.move(x, y)
if __name__ == "__main__":
s = FreenectControlServer()