Untitled
unknown
python
a year ago
2.9 kB
4
Indexable
import socket import pyautogui import time # Configure this with the correct IP and port from Orbits UDP_IP = "127.0.0.1" UDP_PORT = 12345 # Create a UDP socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((UDP_IP, UDP_PORT)) lap_count = 0 race_started = False lap_start_time = None # Track when the lap starts keystroke_delay = 5 # Delay between keystrokes in seconds keystrokes = ['f2', 'f3', 'f4', 'f5'] # Keystrokes to press during a lap # Define the keystroke to be pressed at the start of the lap keystroke_on_race_start = 'f1' # Key to press at the start of a new race print("Listening for data...") while True: data, addr = sock.recvfrom(1024) # Buffer size is 1024 bytes # Convert data to string if necessary data_str = data.decode('utf-8') if 'New Race' in data_str: if race_started: # Reset everything for the new race print(f"New race started. Resetting lap count.") lap_count = 0 race_started = True lap_start_time = None # Reset lap start time keystroke_index = 0 # Index for the current keystroke to be sent is_waiting_for_keystroke = False # Flag to indicate if we are waiting to send the next keystroke if 'Lap' in data_str: if race_started: lap_count += 1 print(f"Laps: {lap_count}") # Press the keystroke for the start of the lap pyautogui.press(keystroke_on_race_start) print(f"Pressed '{keystroke_on_race_start}' for lap start.") # Prepare to start sending keystrokes 5 seconds apart lap_start_time = time.time() # Record the lap start time keystroke_index = 0 # Start with the first keystroke is_waiting_for_keystroke = True # Indicate that we need to send the keystrokes # Check if we need to send a keystroke 5 seconds apart if is_waiting_for_keystroke and lap_start_time: current_time = time.time() elapsed_time = current_time - lap_start_time if keystroke_index < len(keystrokes) and elapsed_time >= keystroke_delay * (keystroke_index + 1): pyautogui.press(keystrokes[keystroke_index]) print(f"Pressed '{keystrokes[keystroke_index]}' {keystroke_delay * (keystroke_index + 1)} seconds after lap start.") keystroke_index += 1 # Move to the next keystroke # If all keystrokes have been sent, stop waiting for keystrokes if keystroke_index >= len(keystrokes): is_waiting_for_keystroke = False # Handle the end of the race if 'Race Over' in data_str: race_started = False lap_start_time = None # Reset lap start time is_waiting_for_keystroke = False # Stop waiting for keystrokes print("Race Over detected. Stopping lap count.")
Editor is loading...
Leave a Comment