-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagicServer.py
More file actions
41 lines (30 loc) · 1.21 KB
/
magicServer.py
File metadata and controls
41 lines (30 loc) · 1.21 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
import pygame, time
import paho.mqtt.client as mqtt
pygame.init()
pygame.display.set_caption(u'Magic Server')
pygame.display.set_mode((600, 600), pygame.RESIZABLE)
mqttc = mqtt.Client()
mqttc.username_pw_set(username="magicSpace", password="magicspace")
mqttc.connect("192.168.0.105")
#mqttc.loop_start()
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEMOTION:
pos = pygame.mouse.get_pos()
print(type(pos))
pos = str(pos[0]) + '$' + str(pos[1])
mqttc.publish('magicSpaceMousePos', pos, qos=0)
#mqttc.publish('magicSpaceMouseY', str(pos[1]), qos=0)
print (pos)
elif event.type == pygame.MOUSEBUTTONDOWN:
print('mouse click')
mqttc.publish('magicSpaceMouse', str(1), qos=0)
#pygame.quit()
elif event.type == pygame.MOUSEBUTTONUP:
print('mouse click release')
mqttc.publish('magicSpaceMouse', str(0), qos=0)
elif event.type == pygame.KEYDOWN:
keystroke = pygame.key.get_pressed()
print(keystroke)
mqttc.publish('magicSpace', keystroke, qos=0)
pygame.quit()