import time
import ctypes

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)
user32.ShowWindow(hwnd, 9)
user32.SetForegroundWindow(hwnd)
user32.BringWindowToTop(hwnd)
time.sleep(0.3)

print("Sending 'O' (VK 0x4F, scan 0x18) to toggle options menu...")
user32.keybd_event(0x4F, 0x18, 0, 0)
time.sleep(0.08)
user32.keybd_event(0x4F, 0x18, 2, 0)
time.sleep(0.8)

import sys
sys.path.insert(0, r"C:\Projects\AutoPOE2")
from tools.autonomous_map_runner import ScreenCapturerGDI
c = ScreenCapturerGDI()
c.capture(r"C:\Projects\AutoPOE2\captures\test_toggle_options_result.png")
print("Captured test_toggle_options_result.png")
