import sys, os
sys.path.insert(0, os.path.abspath('.'))
import time, ctypes
from src.common.win32_window import find_poe2_window, is_poe2_window_focused

user32 = ctypes.windll.user32
poe_hwnd = find_poe2_window()
print(f"POE2 HWND: {hex(poe_hwnd) if poe_hwnd else None}")

for i in range(10):
    fg = user32.GetForegroundWindow()
    cls_buf = ctypes.create_unicode_buffer(256)
    user32.GetClassNameW(fg, cls_buf, 256)
    title_buf = ctypes.create_unicode_buffer(512)
    user32.GetWindowTextW(fg, title_buf, 512)
    focused = is_poe2_window_focused(poe_hwnd)
    safe_title = title_buf.value[:30].encode('ascii', 'replace').decode('ascii')
    print(f"Tick {i:02d}: FG=0x{fg:X} ({cls_buf.value} | '{safe_title}') -> focused={focused}")
    time.sleep(0.5)
