import time
import ctypes
from ctypes import wintypes
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from src.assistant_tool.screen_capturer import ScreenCapturer

capturer = ScreenCapturer(output_dir="captures")
hwnd = capturer.find_poe2_window()
if not hwnd:
    print("Could not find POE2 window")
    sys.exit(1)

capturer.bring_to_foreground(hwnd)
time.sleep(0.2)

# Send key 'I' (VK 0x49, scan code 0x17)
user32 = ctypes.windll.user32
VK_I = 0x49
KEYEVENTF_KEYUP = 0x0002

user32.keybd_event(VK_I, 0x17, 0, 0)
time.sleep(0.05)
user32.keybd_event(VK_I, 0x17, KEYEVENTF_KEYUP, 0)
time.sleep(0.5)

img_path = capturer.capture_screenshot(event_name="INVENTORY_OPEN", capture_ram=False)
print(f"Captured: {img_path}")
