Imagine when a cursor is on a normal part of the page its in the normal state however when its meant to click a button it is in the ready state. Basically theres a button on the screen that I am trying to click however if i have the cursor go immediately to where the button is the cursor remains in the normal state so its unable to click the button. To try to solve this I implemented tweening from a part of the screen that isnt on the button until it gets to the button along with some side to side jitters however the cursor still ends up being in the normal state. If i move my mouse manually over the button even the tiniest movement will make the cursor go into the ready state and make the button clickable. How can i make it so that the cursor will be able to click the button automatically without having me move the cursor myself?
import pyautogui
import time
import random
# Define constants
BREAKTHROUGH_COLOR = (248, 248, 248)
WAIT_TIME_INITIAL = 10
WAIT_TIME_BREAKTHROUGH = 20
WAIT_TIME_BETWEEN_CLICKS = 0.1
# Initial mouse position
INITIAL_POSITION = (956, 644)
# Meditate button position
MEDITATE_POSITION = (960, 980)
def tween_to_position(start_position, end_position, tween_time):
x_start, y_start = start_position
x_end, y_end = end_position
steps = int(tween_time / 0.05) # Number of steps based on a 0.05s interval
for step in range(steps):
progress = step / steps
x = x_start + int((x_end - x_start) * progress)
y = y_start + int((y_end - y_start) * progress)
# Add small random jitters to the left and right
x += random.randint(-5, 5)
pyautogui.moveTo(x, y, duration=0.05)
def common_actions():
# Common actions button position
COMMON_ACTIONS_POSITION = (150, 20)
# Tweening
tween_to_position(COMMON_ACTIONS_POSITION, (75, 20), tween_time=2)
time.sleep(1) # Add a delay before the click
pyautogui.click(75, 20, clicks=3, interval=WAIT_TIME_BETWEEN_CLICKS)
while True:
time.sleep(WAIT_TIME_INITIAL)
if pyautogui.pixel(*INITIAL_POSITION) == BREAKTHROUGH_COLOR:
print("Breakthrough ready")
# Tweening for the breakthrough button
tween_to_position((956, 400), INITIAL_POSITION, tween_time=2)
pyautogui.click(*INITIAL_POSITION, clicks=5, interval=WAIT_TIME_BETWEEN_CLICKS) # Increase the number of clicks
print("Waiting for breakthrough")
time.sleep(WAIT_TIME_BREAKTHROUGH)
print("Meditating")
# Tweening for the meditation button
tween_to_position((960, 900), MEDITATE_POSITION, tween_time=2)
pyautogui.click(*MEDITATE_POSITION, clicks=5, interval=WAIT_TIME_BETWEEN_CLICKS) # Increase the number of clicks
else:
print("Not ready")
common_actions()
I've tried many things. I tried having the point where the cursor is meant to click be on the edge of the button then making the cursor go in a circle and end up at the edge of the button to try to make it work. I tried adding a random squiggle from one location of the screen to the button. I've tried using a sine wave to make the cursor move in an S like pattern to the position of the button. I've tried moving the cursor more linearly. I've tried micro movements over the button. None of these solutions seemed to fix the problem I'm facing of having the cursor not register that it is hovering over the button. I would really appreciate any help you could provide me. Thank you