-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
69 lines (66 loc) · 2.14 KB
/
server.py
File metadata and controls
69 lines (66 loc) · 2.14 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
65
66
67
68
69
import socket
from pynput.mouse import Controller as MouseController
from pynput.keyboard import Controller as KeyboardController
from pynput.keyboard import Key
from pynput.mouse import Button
import json
from screeninfo import get_monitors
from config import *
mouseController = MouseController()
keyboardController = KeyboardController()
name = "JT-Laptop"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(server)
data = ""
while True:
data, addr = s.recvfrom(1024)
data = data.decode('utf-8')
data = json.loads(data)
print(json.dumps(data, indent=4))
if data["target"] != name:
continue
if data["message"] == "info":
for m in get_monitors():
if m.is_primary:
s.sendto(json.dumps({
"x": m.x,
"y": m.y,
"width": m.width,
"height": m.height,
"width_mm": m.width_mm,
"height_mm": m.height_mm
}).encode("utf-8"), client)
break
elif data["message"] == "mouse":
x = data["coords"]["x"]
y = data["coords"]["y"]
mouseController.position = (x, y)
elif data["message"] == "press":
keycode = data["keycode"]
for k in Key:
if str(k) == keycode:
keyboardController.press(k)
break
else:
keyboardController.press(keycode.strip("\'"))
elif data["message"] == "unpress":
keycode = data["keycode"]
for k in Key:
if str(k) == keycode:
keyboardController.release(k)
break
else:
keyboardController.release(keycode.strip("\'"))
# keyboardController.tap(KeyCode.from_vk(keycode))
elif data["message"] == "button":
button = data["button"]
for b in Button:
if str(b) == button:
mouseController.press(b)
elif data["message"] == "unbutton":
button = data["button"]
for b in Button:
if str(b) == button:
mouseController.release(b)
elif data["message"] == "quit":
break