Когда курсор перемещается из одного места в другое, как только он достигает конечного пункта назначения, курсор не обнарPython

Программы на Python
Ответить Пред. темаСлед. тема
Гость
 Когда курсор перемещается из одного места в другое, как только он достигает конечного пункта назначения, курсор не обнар

Сообщение Гость »


Представьте, что курсор находится в обычной части страницы, он находится в нормальном состоянии, однако когда он предназначен для нажатия кнопки, он находится в состоянии готовности. По сути, на экране есть кнопка, которую я пытаюсь нажать, однако, если у меня есть курсор, который сразу же перемещается туда, где находится кнопка, курсор остается в нормальном состоянии, поэтому он не может нажать кнопку. Чтобы попытаться решить эту проблему, я реализовал анимацию той части экрана, которая не находится на кнопке, пока она не дойдет до кнопки вместе с некоторым дрожанием из стороны в сторону, однако курсор все равно оказывается в нормальном состоянии. Если я вручную наведу указатель мыши на кнопку, даже малейшее движение приведет к тому, что курсор перейдет в состояние готовности и кнопка станет доступной для нажатия. Как я могу сделать так, чтобы курсор мог автоматически нажимать кнопку, не перемещая курсор самому?

Код: Выделить всё

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


Источник: https://stackoverflow.com/questions/781 ... -its-final
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»