-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
64 lines (51 loc) · 1.91 KB
/
client.py
File metadata and controls
64 lines (51 loc) · 1.91 KB
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
import socket
from functools import partial
import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.properties import NumericProperty, ReferenceListProperty,ObjectProperty
from kivy.core.window import Window
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_ip = '192.168.177.45'
server_port = 2345
server = (server_ip, server_port)
class Touch(Widget):
count = NumericProperty(1)
click_type = NumericProperty(0)
right_click_event = ObjectProperty(0)
def on_touch_down(self, touch):
self.right_click_event =Clock.schedule_once(partial(self.right_click, touch), 1.5)
if touch.is_double_tap:
self.click_type = 1
msg = str(round(touch.x))+":"+str(round(touch.y))+":"+str(self.click_type)
print(msg)
s.sendto(msg.encode(), server)
elif touch.is_triple_tap:
self.click_type = 2
msg = str(round(touch.x))+":"+str(round(touch.y))+":"+str(self.click_type)
print(msg)
s.sendto(msg.encode(), server)
else:
self.click_type = 0
msg = str(round(touch.x))+":"+str(round(touch.y))+":"+str(self.click_type)
print(msg)
s.sendto(msg.encode(), server)
def on_touch_up(self, touch):
self.click_type = 0
Clock.unschedule(self.right_click_event)
def on_touch_move(self, touch):
Clock.unschedule(self.right_click_event)
msg = str(round(touch.x))+":"+str(round(touch.y))+":"+str(self.click_type+4)
print(msg)
s.sendto(msg.encode(), server)
def right_click(self, touch, count):
self.click_type = 3
msg = str(round(touch.x))+":"+str(round(touch.y))+":"+str(self.click_type)
print(msg)
s.sendto(msg.encode(), server)
self.click_type = 0
class MyApp(App):
def build(self):
return Touch()
MyApp().run()