import pyautogui import keyboard import time import pygame from PIL import ImageGrab…
- User
`import pyautogui import keyboard import time import pygame from PIL import ImageGrab import configparser
CONFIGS
config = configparser.ConfigParser() config.read('config.ini') volume = config.getfloat('Settings', 'volume') check_iterrations = config.getint('Settings', 'check_iterrations') bad_signal = tuple(map(int, config.get('Settings', 'bad_signal').split(', '))) hold_time = config.getfloat('Settings', 'hold_time') sleeptime = config.getfloat('Settings', 'sleeptime') clicktime = config.getfloat('Settings', 'clicktime')
Get resolution
screen_width, screen_height = pyautogui.size()
PERCENT COORDINATES
radius_x = 56 radius_y = 74
signal_x = 36 signal_y = 37
tumbler_x = 71 tumbler_y = 73
search_x = 33 search_y = 53
mouse_swipe_x = 10 mouse_swipe_y = 0
OTHER
bad_signal = (42, 65, 38) # лампочка не горит
bad_signal = (81, 99, 77) # raduga
pygame.mixer.init()
convert percent to pixels
def convert_p2p(x, y): res_x = int(screen_width * (x / 100)) res_y = int(screen_height * (y / 100)) result = (res_x, res_y) return result
def presearch(): time.sleep(hold_time) pyautogui.click() search = convert_p2p(search_x, search_y) pyautogui.moveTo(search[0], search[1]) pyautogui.click() pygame.mixer.music.load('audio/fail.mp3') pygame.mixer.music.set_volume(volume) pygame.mixer.music.play() keyboard.wait('home') print('Нажми кнопку HOME в открытой игре, чтобы перезагрузить скрипт для дальнейшего поиска') main_action()
def main_action(): # Нажатие кнопки 'X' pyautogui.press('X')
code# Перемещение к целевой области и нажатие radius = convert_p2p(radius_x, radius_y) time.sleep(clicktime) pyautogui.moveTo(radius[0], radius[1]) pyautogui.click() # Вычисление цвета лампы сигнала signal = convert_p2p(signal_x, signal_y) # конвертация координатов сигнала с процентов в px iterr_count = 0 while iterr_count < check_iterrations: iterr_count += 1 screen = ImageGrab.grab() color = screen.getpixel((signal[0], signal[1])) print(f'{iterr_count} / {check_iterrations}') print(f'* Signal color: {color}') # file_path = f'screenshot_{iterr_count}.png' # screen.save(file_path) if color == bad_signal: print('*** NO SIGNAL') else: print('HAVE A GREEN SIGNAL!') pygame.mixer.music.load('audio/success.mp3') pygame.mixer.music.set_volume(volume) pygame.mixer.music.play() tumbler = convert_p2p(tumbler_x, tumbler_y) pyautogui.moveTo(tumbler[0], tumbler[1]) pyautogui.click() presearch() pyautogui.press('x') time.sleep(sleeptime) main_action() - Assistant
When
pyautogui.press('X')isn't working, it usually means that the script might not be correctly interacting with the intended application or the application is not registering the key press. Here are a few steps to troubleshoot and potentially fix the issue:-
Check Active Window: Ensure that the window you want PyAutoGUI to interact with is the active window. PyAutoGUI will send key presses to the currently active window, and if your application is not in focus, it won't receive the input.
-