asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.22k forks source link

Method Click move cursor. #842

Open JC-WebInfo opened 5 months ago

JC-WebInfo commented 5 months ago

I try to make bots for Modded Minecraft 1.16.2(modpack RAD2).

When i use pyautogui.click(), the cursor move inside Minecraft before clicking.

Minecraft: 1.16.2 (modpack RAD2, https://www.curseforge.com/minecraft/modpacks/roguelike-adventures-and-dungeons-2 ) Python: 3.10.12 Pyautogui: 0.9.54

Step to reproduct it: 1)Launch minecraft, load a world, pause game 2)open python 2)type in python:

from time import sleep
import pyautogui
sleep(5);pyautogui.click()

3)return to minecraft, unpause it 4)wait 5 seconds 5)TADA !

darkb0ts commented 5 months ago

"When you use python -m mouseinfo or python3 -m mouseinfo, you will receive the x and y coordinates for clicking. For example: x-100, y-150."

example:

import pyautogui
import time
time.sleep(5)
pyautogui.moveTo(100, 150) 
pyautogui.click()
JC-WebInfo commented 5 months ago

so i need to get mouse coordonnate, move at them to avoid the random move? Like this example?

from time import sleep
import pyautogui
sleep(5);
x,y = pyautogui.position()
pyautogui.moveTo(x, y) 
pyautogui.click()