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

18
main.py
View file

@ -6,6 +6,14 @@ import sys
import libevdev import libevdev
#from libevdev import ecodes #from libevdev import ecodes
MULTICAST_TTL = 4 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): def main(device_path, dest_ip, dest_port):
""" """
Reads absolute X and Y coordinates from an evdev device and sends them 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 # Variables to store the latest coordinates
x_coor = None x_coor = None
y_coor = None y_coor = None
send(69,69)
send(69,69)
# Loop indefinitely to read events # Loop indefinitely to read events
while True: while True:
for e in d.events(): for e in d.events():
@ -53,12 +62,7 @@ def main(device_path, dest_ip, dest_port):
# The format string 'HH' specifies two unsigned short integers (u16). # The format string 'HH' specifies two unsigned short integers (u16).
# The '<' character ensures little-endian byte order. # The '<' character ensures little-endian byte order.
try: try:
packet = struct.pack('<HH', int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080)) send(sock,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 # Reset coordinates to wait for the next pair of events
x_coor = None x_coor = None
y_coor = None y_coor = None