my script

from pynput.keyboard import Key, Controller
import time
import re
import sys
import pygetwindow as gw
import psutil
import pyperclip
import win32gui
import win32process

def get_numbers():
    """
    Collect numbers from user input, allowing multiple lines of input.
    Users can enter numbers separated by semicolons, commas, or newlines.
    Press Enter on an empty line to finish input.
    """
    print(
        "\nEnter the numbers to paste in Geo Zeb (separated by semicolons, commas, or newlines):\n"
        "(Press Enter on an empty line to finish input)"
    )
    numbers = []
    while True:
        try:
            line = input()
            if not line.strip():
                break
            # Split the line on semicolons, commas, and strip whitespace
            split_numbers = re.split(r'[;,]+', line)
            # Strip each number and filter out empty strings
            split_numbers = [num.strip() for num in split_numbers if num.strip()]
            # Validate each number
            valid_numbers = [num for num in split_numbers if validate_number(num)]
            invalid_numbers = set(split_numbers) - set(valid_numbers)
            if invalid_numbers:
                print(f"Invalid entries skipped: {', '.join(invalid_numbers)}")
            numbers.extend(valid_numbers)
        except KeyboardInterrupt:
            print("\nInput interrupted by user.")
            break
        except Exception as e:
            print(f"An error occurred during input: {e}")
            break
    print(f"\nTotal valid numbers collected: {len(numbers)}")
    return numbers

def validate_number(number):
    """
    Validate if the input string is a valid number (integer or float).
    """
    try:
        float(number)
        return True
    except ValueError:
        return False

def press_and_release(key, pause=0.01):
    """
    Press and release a key with an optional pause.
    """
    try:
        keyboard.press(key)
        keyboard.release(key)
        time.sleep(pause)
    except Exception as e:
        print(f"Error pressing key {key}: {e}")

def press_keys(keys, pause=0.01):
    """
    Press and release multiple keys simultaneously.
    """
    try:
        for key in keys:
            keyboard.press(key)
        time.sleep(pause)
        for key in reversed(keys):
            keyboard.release(key)
        time.sleep(pause)
    except Exception as e:
        print(f"Error pressing keys {keys}: {e}")

def ensure_target_focused(window_title, executable_name, timeout=10):
    """
    Ensure that the target application window is focused.

    :param window_title: The title of the target application window.
    :param executable_name: The executable name of the target application.
    :param timeout: Time in seconds to wait for the window to appear and be focused.
    :return: True if the window is focused, False otherwise.
    """
    start_time = time.time()
    while time.time() - start_time < timeout:
        try:
            windows = gw.getWindowsWithTitle(window_title)
            if not windows:
                print(f"Waiting for '{window_title}' window to appear...")
                time.sleep(0.5)
                continue
            window = windows[0]
            hwnd = window._hWnd  # Window handle
            if not hwnd:
                print("Could not retrieve the window handle.")
                time.sleep(0.5)
                continue
            # Get process ID associated with the window
            try:
                _, pid = win32process.GetWindowThreadProcessId(hwnd)
                process = psutil.Process(pid)
                exe_name = process.name()
            except psutil.NoSuchProcess:
                print("No process found with the retrieved process ID.")
                time.sleep(0.5)
                continue
            except Exception as e:
                print(f"Error retrieving process information: {e}")
                time.sleep(0.5)
                continue
            # Verify executable name
            if exe_name.lower() != executable_name.lower():
                print(f"Found window titled '{window_title}' but executable is '{exe_name}'. Expected '{executable_name}'.")
                time.sleep(0.5)
                continue
            # Bring the window to the front
            window.activate()
            print(f"Focusing window: '{window_title}'")
            time.sleep(0.5)  # Wait for the window to come to focus
            return True
        except Exception as e:
            print(f"Error focusing window: {e}")
            time.sleep(0.5)
    print(f"Failed to focus the target application '{window_title}' within {timeout} seconds.")
    return False

def paste_numbers(numbers, cells_per_row=3, pause_between_pastes=0.05):
    """
    Paste numbers into Geo Zeb (or similar application) using keyboard automation.
    Assumes that the target application expects numbers to be entered in cells,
    moving to the next cell with the Tab key, and starting a new row after every 'cells_per_row' numbers.

    :param numbers: List of valid numbers to paste.
    :param cells_per_row: Number of cells before moving to the next row.
    :param pause_between_pastes: Delay between paste actions in seconds.
    """
    total_numbers = len(numbers)
    print(f"\nStarting to paste {total_numbers} numbers into Geo Zeb...")

    if total_numbers == 0:
        print("No numbers to paste.")
        return

    # Ensure the target application is focused
    target_title = "Geo Zeb"
    executable_name = "DMiniTools.exe"
    if not ensure_target_focused(target_title, executable_name):
        print("Cannot proceed without focusing the target application.")
        return

    # Make the first cell editable
    press_and_release(Key.f2)

    # Initialize counter
    count = 0

    for index, number in enumerate(numbers, start=1):
        try:
            # Type the number
            keyboard.type(number)
            time.sleep(0.01)  # Small pause to ensure typing is registered

            # Press Tab to move to the next cell
            press_and_release(Key.tab)

            count += 1
            # Progress Indicator
            print(f"Pasted {count}/{total_numbers} numbers...", end='\r')

            if count % cells_per_row == 0 and count != total_numbers:
                # After every 'cells_per_row' numbers, move to the next row
                press_and_release(Key.tab)  # Adjust based on how Geo Zeb handles new rows
                time.sleep(0.01)  # Slightly longer pause for row transition
                press_and_release(Key.f2)  # Make the new cell editable

            time.sleep(pause_between_pastes)  # Adjust the delay as needed

        except Exception as e:
            print(f"\nError during pasting number {number}: {e}")
            continue

    # Final action after all numbers are pasted
    # Press 'Space' to activate 'check transformation precision' button
    press_and_release(Key.space)
    time.sleep(0.1)

    # Return to 'point 0 local X' cell
    press_keys([Key.ctrl, Key.home])  # Press 'Ctrl + Home'
    time.sleep(0.1)
    press_and_release(Key.tab)        # Press 'Tab' to move to 'X' cell
    time.sleep(0.1)
    press_and_release(Key.f2)         # Press 'F2' to make it editable
    time.sleep(0.1)

    print(f"\nPasting completed: {count}/{total_numbers} numbers pasted successfully.")

def main():
    """
    Main function to execute the paste operation.
    Allows the script to remain open for multiple paste actions.
    """
    print("=== Geo Zeb Number Paster ===")
    while True:
        try:
            numbers = get_numbers()
            if numbers:
                paste_numbers(numbers)
            else:
                print("No valid numbers entered. Please try again.")

            # Ask the user if they want to perform another paste action
            choice = input("\nDo you want to paste another set of numbers? (y/n): ").strip().lower()
            if choice != 'y':
                print("Exiting the script. Goodbye!")
                break
        except KeyboardInterrupt:
            print("\nScript interrupted by user. Exiting...")
            break
        except Exception as e:
            print(f"An unexpected error occurred: {e}")
            break

if __name__ == '__main__':
    keyboard = Controller()
    main()

it alll finished well after executing it. so it is working as intened. what i want is that after executin the last 'space' key press the script keyboard goes back to the first cell of Geo Zeb, the software in which i'm using the script to paste numbers in.
to do that there are 2 'cntrl+home' to be pressed and 1 tab keypress, than the usual and initial script flow that starts with F2.