import ctypes
import ctypes.wintypes as w
import struct
import time
import subprocess
import win32gui
import win32con
from PIL import ImageGrab

u32 = ctypes.windll.user32

hdesk = u32.OpenDesktopW("Default", 0, False, 0x10000000)
if not hdesk:
    hdesk = u32.OpenInputDesktop(0, False, 0x10000000)
if hdesk:
    u32.SetThreadDesktop(hdesk)

hwnd = win32gui.FindWindow("POEWindowClass", "Path of Exile 2")
if hwnd:
    win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
    win32gui.SetForegroundWindow(hwnd)
    time.sleep(0.3)

# Scroll DOWN 20 times to zoom out
print("Scrolling wheel DOWN 20 times...")
for _ in range(20):
    u32.mouse_event(0x0800, 0, 0, -120, 0)
    time.sleep(0.05)

time.sleep(0.5)

img = ImageGrab.grab(all_screens=True)
img.save("captures/scrolled_with_8_clamp.png")
print("Saved captures/scrolled_with_8_clamp.png")
