import ctypes, win32gui, win32process, psutil

user32 = ctypes.windll.user32
hdesk = user32.OpenInputDesktop(0, False, 0x01FF)
if hdesk: user32.SetThreadDesktop(hdesk)

print("=== PROCESSES ===")
for p in psutil.process_iter(['pid', 'name']):
    n = p.info['name'].lower() if p.info['name'] else ''
    if any(x in n for x in ['game', 'sword', 'autoupdate', 'jx', 'vggame']):
        print(f"PID {p.info['pid']}: {p.info['name']}")

print("\n=== SWORD3 WINDOWS ===")
windows = []
def cb(h, _):
    if win32gui.GetClassName(h) == 'Sword3 Class':
        _, pid = win32process.GetWindowThreadProcessId(h)
        vis = win32gui.IsWindowVisible(h)
        rect = win32gui.GetWindowRect(h)
        title = win32gui.GetWindowText(h)
        windows.append((h, pid, title, vis, rect))
win32gui.EnumWindows(cb, None)

for h, pid, title, vis, rect in windows:
    print(f"HWND: 0x{h:08X}, PID: {pid}, Visible: {vis}, Title: '{title}', Rect: {rect}")
