This commit is contained in:
0m.ax 2025-07-20 16:18:31 +02:00
parent fe8156c1a7
commit 323b3bc45a

20
main.py
View file

@ -6,6 +6,14 @@ import sys
import libevdev
#from libevdev import ecodes
MULTICAST_TTL = 4
def send(socket,x,y):
packet = struct.pack('<HH', int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080))
# Send the packet over UDP
sock.sendto(packet, (dest_ip, dest_port))
print(f"Sent {len(packet)} bytes.")
def main(device_path, dest_ip, dest_port):
"""
Reads absolute X and Y coordinates from an evdev device and sends them
@ -34,7 +42,8 @@ def main(device_path, dest_ip, dest_port):
# Variables to store the latest coordinates
x_coor = None
y_coor = None
send(69,69)
send(69,69)
# Loop indefinitely to read events
while True:
for e in d.events():
@ -53,13 +62,8 @@ def main(device_path, dest_ip, dest_port):
# The format string 'HH' specifies two unsigned short integers (u16).
# The '<' character ensures little-endian byte order.
try:
packet = struct.pack('<HH', int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080))
# Send the packet over UDP
sock.sendto(packet, (dest_ip, dest_port))
print(f"Sent {len(packet)} bytes.")
# Reset coordinates to wait for the next pair of events
send(sock,int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080))
# Reset coordinates to wait for the next pair of events
x_coor = None
y_coor = None