initial commit
This commit is contained in:
25
pc.py
Normal file
25
pc.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import socket
|
||||||
|
from pynput.mouse import Controller
|
||||||
|
|
||||||
|
mouse = Controller()
|
||||||
|
|
||||||
|
HOST = '0.0.0.0'
|
||||||
|
PORT = 2025
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
sock.bind((HOST, PORT))
|
||||||
|
|
||||||
|
print(f"listening on {HOST}:{PORT}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
data, addr = sock.recvfrom(1024)
|
||||||
|
x_str, y_str = data.decode().split(',')
|
||||||
|
x = float(x_str)
|
||||||
|
y = float(y_str)
|
||||||
|
mouse.position = (x, y)
|
||||||
|
print(f"Moved mouse to: X={x}, Y={y}")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("UDP server shutting down.")
|
||||||
|
finally:
|
||||||
|
sock.close()
|
||||||
25
terra.py
Normal file
25
terra.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import socket
|
||||||
|
import time
|
||||||
|
from pynput.mouse import Controller
|
||||||
|
|
||||||
|
mouse = Controller()
|
||||||
|
print("PC IP:")
|
||||||
|
SERVER_IP = input()
|
||||||
|
PORT = 2025
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
|
||||||
|
try:
|
||||||
|
last_pos = None
|
||||||
|
while True:
|
||||||
|
pos = mouse.position
|
||||||
|
if pos != last_pos:
|
||||||
|
message = f"{pos[0]},{pos[1]}"
|
||||||
|
sock.sendto(message.encode(), (SERVER_IP, PORT))
|
||||||
|
print("Sent:", message)
|
||||||
|
last_pos = pos
|
||||||
|
time.sleep(0.05)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("UDP client stopped.")
|
||||||
|
finally:
|
||||||
|
sock.close()
|
||||||
Reference in New Issue
Block a user