import time
import ctypes

def main():
    user32 = ctypes.windll.user32
    hwinsta = user32.OpenWindowStationW("WinSta0", False, 0x10000000)
    if hwinsta:
        user32.SetProcessWindowStation(hwinsta)
    hdesk = user32.OpenDesktopW("Default", 0, False, 0x10000000)
    if hdesk:
        user32.SetThreadDesktop(hdesk)

    hwnd = user32.FindWindowW("POEWindowClass", None)
    if not hwnd:
        hwnd = user32.FindWindowW(None, "Path of Exile 2")
    if hwnd:
        user32.ShowWindow(hwnd, 9)
        user32.SetForegroundWindow(hwnd)
        time.sleep(0.2)
        # Send ESC
        user32.keybd_event(0x1B, 0, 0, 0)
        time.sleep(0.06)
        user32.keybd_event(0x1B, 0, 2, 0)
        time.sleep(0.2)
        # Move cursor to upper center (1280, 500)
        user32.SetCursorPos(1280, 500)
        time.sleep(0.1)
        print("Sent ESC and moved cursor to (1280, 500)")

if __name__ == "__main__":
    main()
