# -*- coding: utf-8 -*- from scriptBase.imgFind import pcacc_img from scriptBase.mouseClick import pcacc_mouse import scriptBase.comon as comon import subprocess import pyautogui import random import string import time import pygetwindow as gw pic_notepad = 'other\other_notepad.png' pic_calc = 'other\other_calc.png' pic_edge = 'other\other_edge.png' # 生成随机字符串 def generate_random_string(length): letters = string.ascii_letters + string.digits # 包含字母和数字的字符集 return ''.join(random.choice(letters) for _ in range(length)) def typeRandomStr(str): random_string = str if len(random_string) == 0: random_string = generate_random_string(random.randint(50, 100)) for char in random_string: pyautogui.typewrite(char) delay = random.uniform(0.1, 0.3) # 生成随机延迟时间 time.sleep(delay) class doOtherThing: @staticmethod def doWithNotePad(): app_path = "notepad.exe" subprocess.Popen(app_path) comon.myTimeSleep_big() ret, position = pcacc_img.find_img_position(pic_notepad) if ret: point1, point2 = pcacc_img.choose_two_point_from_position(position) pcacc_mouse.click(point1[0], point1[1]) comon.myTimeSleep_small() typeRandomStr('') pyautogui.scroll(random.randint(-20, 20)) pcacc_mouse.drag(point2[0], point2[1]) comon.myTimeSleep_big() subprocess.call(f"taskkill /f /im {app_path}") @staticmethod def doWithCalc(): app_path = "calc.exe" subprocess.Popen(app_path) comon.myTimeSleep_big() if comon.waitClickImg_noWait(pic_calc, 1, 0): comon.myTimeSleep_big() operators = ['+', '-', '*', '/'] random_str = str(random.randint(100, 200)) + random.choice(operators) + str(random.randint(100, 200)) + random.choice(operators) typeRandomStr(random_str) comon.myTimeSleep_big() subprocess.call(f"taskkill /f /im CalculatorApp.exe") @staticmethod def doWithEdge(): if comon.waitClickImg_noWait(pic_edge, 2, 0): comon.myTimeSleep_big() pyautogui.scroll(random.randint(-20, 20)) comon.myTimeSleep(60) pyautogui.scroll(random.randint(-20, 20)) comon.myTimeSleep(60) comon.waitClickImg_noWait(pic_edge, 2, 0) OtherThingFuncArr = [doWithNotePad, doWithCalc] if __name__ == '__main__': doOtherThing.doWithEdge()