Update client.py
This commit is contained in:
30
client.py
30
client.py
@@ -1,7 +1,15 @@
|
|||||||
import socket
|
import socket
|
||||||
from pynput.mouse import Controller
|
import time
|
||||||
|
from evdev import UInput, ecodes as e
|
||||||
|
|
||||||
mouse = Controller()
|
# Create a virtual mouse device
|
||||||
|
ui = UInput(
|
||||||
|
{
|
||||||
|
e.EV_REL: [e.REL_X, e.REL_Y],
|
||||||
|
e.EV_KEY: [e.BTN_LEFT, e.BTN_RIGHT]
|
||||||
|
},
|
||||||
|
name='virtual-mouse'
|
||||||
|
)
|
||||||
|
|
||||||
HOST = '0.0.0.0'
|
HOST = '0.0.0.0'
|
||||||
PORT = 2025
|
PORT = 2025
|
||||||
@@ -9,17 +17,23 @@ PORT = 2025
|
|||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock.bind((HOST, PORT))
|
sock.bind((HOST, PORT))
|
||||||
|
|
||||||
print(f"listening on {HOST}:{PORT}")
|
print(f"Listening on {HOST}:{PORT}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = sock.recvfrom(1024)
|
||||||
x_str, y_str = data.decode().split(',')
|
x_str, y_str = data.decode().split(',')
|
||||||
x = float(x_str)
|
dx = int(float(x_str))
|
||||||
y = float(y_str)
|
dy = int(float(y_str))
|
||||||
mouse.position = (x, y)
|
|
||||||
print(f"Moved mouse to: X={x}, Y={y}")
|
# Note: uinput typically handles relative motion (REL_X / REL_Y)
|
||||||
|
ui.write(e.EV_REL, e.REL_X, dx)
|
||||||
|
ui.write(e.EV_REL, e.REL_Y, dy)
|
||||||
|
ui.syn()
|
||||||
|
|
||||||
|
print(f"Moved mouse relative: dX={dx}, dY={dy}")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("UDP server shutting down.")
|
print("\nUDP server shutting down.")
|
||||||
finally:
|
finally:
|
||||||
|
ui.close()
|
||||||
sock.close()
|
sock.close()
|
||||||
Reference in New Issue
Block a user