Untitled
unknown
python
2 years ago
2.2 kB
5
Indexable
# -*- coding: utf-8 -*- import os, shutil, subprocess, time, keyboard, pyautogui, time import numpy as np from mss import mss import pyautogui as pg def find_color(our_color, monitor={}): # Возмём кусок экрана m = mss() # Получаем пиксель с экрана монитора img = m.grab(monitor) # Преобразуем этот пиксель в матрицу img_arr = np.array(img) # Поиск цвета (b, g, r, alpha) our_map = (our_color[2], our_color[1], our_color[0], 255) indexes = np.where(np.all(img_arr == our_map, axis=-1)) our_crd = np.transpose(indexes) return our_crd def search_color(our_color): time1 = time.time() result = find_color(our_color, monitor) time2 = time.time() if result.__len__(): x = result[0][1] + monitor.get('left') y = result[0][0] + monitor.get('top') print(time2 - time1, [x, y]) pyautogui.click(x, y) else: return False def waitforcolor(color): i=0 while i<20: i=i+1 is_click_done = search_color(our_color) if is_click_done==False: print('Не нажали кнопку 1') time.sleep(2) else: print('Нажали кнопку 1') return True i=i+21 time.sleep(3) else: return False def colorclick(our_color): if waitforcolor(our_color)==True: print('Переходим к следующему клику') else: print('Скрипт сломался. RIP') quit() time.sleep(1) monitor = { "left": 404, "top": 110, "width": 1200, "height": 730, } colorclick([182, 182, 182]) colorclick([181, 128, 226]) colorclick([237, 159, 32]) colorclick([86, 179, 245]) pyautogui.keyDown('ctrl') pyautogui.press('a') pyautogui.keyUp('ctrl') time.sleep(1) with open('D:/converter/name.txt', 'r') as f: filecontent = f.readlines() first_element = filecontent[0] del filecontent[0] with open('D:/converter/name.txt', 'w') as f: for line in filecontent: f.write(line) pyautogui.write(first_element) #keyboard.press("esc") #time.sleep(2)
Editor is loading...