-
Notifications
You must be signed in to change notification settings - Fork 5
/
receive.py
75 lines (60 loc) · 2.06 KB
/
receive.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
70
71
72
73
74
75
import socket
import time
import select
import keyboard
LISTEN_IP = ""
RCV_PORT = 8081
sockrcv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sockrcv.bind((LISTEN_IP, RCV_PORT))
#sockrcv.settimeout(0)
while True:
try:
data, addr = sockrcv.recvfrom(1024) # buffer size is 1024 bytes
tmp = data.decode("utf-8")
print(tmp)
if tmp == "Y+":
keyboard.press('up')
if tmp == "STOPY+":
keyboard.release('up')
if tmp == "Y-":
keyboard.press('down')
if tmp == "STOPY-":
keyboard.release('down')
if tmp == "X-":
keyboard.press('left')
if tmp == "STOPX-":
keyboard.release('left')
if tmp == "X+":
keyboard.press('right')
if tmp == "STOPX+":
keyboard.release('right')
if tmp == "Z+":
keyboard.press('page up')
if tmp == "STOPZ+":
keyboard.release('page up')
if tmp == "Z-":
keyboard.press('page down')
if tmp == "STOPZ-":
keyboard.release('page down')
if tmp == "X0":
keyboard.press_and_release('alt+x')
if tmp == "Y0":
keyboard.press_and_release('alt+y')
if tmp == "Z0":
keyboard.press_and_release('alt+z')
if tmp == "HOME":
keyboard.press_and_release('ctrl+home')
if tmp == "ZPROBE":
keyboard.press_and_release('F4')
if tmp == "RESET":
keyboard.press_and_release('space')
if tmp == "PLAY":
keyboard.press_and_release('alt+r')
if tmp == "PAUSE":
keyboard.press_and_release('alt+p')
if tmp == "STOP":
keyboard.press_and_release('alt+s')
except KeyboardInterrupt:
print("End")
# If you actually want the program to exit
raise