I’m trying to make some sort of mouse & keyboard a macro recorder like Pulover’s of TinyTask. However, the game I’m doing it for (Minecraft) has its screen locked in the middle. I’ve looked into PyAutoGUI, but I believe the way it detects input is by reading the coordinates on your screen. Since the screen will be locked in place, the coordinates will always remain the same, which means I won’t be able to detect mouse movement.
https://devcodef1.com/news/1029653/detecting-mouse-movement-in-python contains something similar I’m trying to do. Unfortunately this is only for PyGame and it will not detect input unless the window is focused.
What I’ve tried before is reading the mouse movements every 0.001 seconds get 2 x or y inputs, subtract to find the delta, and putting it inside a list:
import pyautogui
import time
x_coords = []
y_coords = []
base_position_x, base_position_y = pyautogui.position()
while True:
current_position_x, current_position_y = pyautogui.position()
change_x = current_position_x - base_position_x
change_y = current_position_y - base_position_x
x_coords.append(change_x)
y_coords.append(change_y)
base_position_x, base_position_y = current_position_x, current_position_y
time.sleep(0.01)
However, this will not playback with 100% accuracy:
for x, y in zip(x_coords, x_coords)
pyautogui.move(x, y)
time.sleep(0.01)
This produces some “jittery” and “slow” movements inside Minecraft, and I need it to be 100% accurate.
fofo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.