-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (24 loc) · 869 Bytes
/
main.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
from fastapi import FastAPI, WebSocket
import pyautogui
app = FastAPI()
@app.websocket('/remote')
async def remote(websocket: WebSocket):
tv_width = 0
tv_height = 0
screen_size = pyautogui.size()
mac_width = screen_size.width
mac_height = screen_size.height
await websocket.accept()
while True:
data = await websocket.receive_json()
print(data)
if data['event'] == 'register_tv_size':
tv_width = data['payload']['x']
tv_height = data['payload']['y']
elif data['event'] == 'mouseMove':
if 'payload' in data:
x = data['payload']['x']
y = data['payload']['y']
actual_x = (mac_width * x) / tv_width
actual_y = (mac_height * y) / tv_height
pyautogui.moveTo(actual_x, actual_y, _pause=False)