Wilson Nogueira
Wilson Nogueira

Reputation: 1

Dual Monitor Mouse Cursor PyAutoGui

Hey, I'm using this code, and I have a dual monitor (dimensions: 1920x1080 and 1080x1920), but when I run this code, only applies to first/main monitor 1920x1080

import pyautogui
import time
import pyscreenshot
import os

image_path = "C:\\Users\\wilso\\OneDrive\\Documentos\\bot pixels\\jumebara.png"

monitor_resolutions = [(1920, 1080), (1080, 1920)]

procurar = "sim"

while procurar == "sim":
    for resolution in monitor_resolutions:
        # Set screenshot region based on current monitor resolution
        screenshot = pyscreenshot.grab(bbox=(0, 0, resolution[0], resolution[1]))

        # Search for the button "Criar"
        try:
            img = pyautogui.locateCenterOnScreen(image_path, confidence=0.7)
            if img:
                # Click on the center of the button
                pyautogui.click(img.x, img.y)
                print(f"Botão 'Criar' encontrado e clicado no monitor {resolution}")
        except:
            print(f"Erro ao procurar botão 'Criar' no monitor {resolution}")

        # Search for the button "Coletar"
        try:
            img = pyautogui.locateCenterOnScreen(image_path, confidence=0.5)
            if img:
                # Click on the center of the button
                pyautogui.click(img.x, img.y)
                print(f"Botão 'Coletar' encontrado e clicado no monitor {resolution}")
        except:
            print(f"Erro ao procurar botão 'Coletar' no monitor {resolution}")

    # Await for next iteration
    time.sleep(1)

print("Finalizando execução")

I tried rewriting, but no success

Upvotes: 0

Views: 31

Answers (0)

Related Questions