def print_mouse_position(): prev_pos = pyautogui.Point(0, 0) curr_pos = pyautogui.Point(0, 0) while True: prev_pos = curr_pos curr_pos = pyautogui.position() if curr_pos != prev_pos: print('position: ', curr_pos)
def adminSwipe(): homecard = pyautogui.Point(x=530, y=583) second = pyautogui.Point(x=347, y=296) final = pyautogui.Point(x=1148, y=285) time.sleep(1) Use() pyautogui.click(homecard.x, homecard.y) time.sleep(1) pyautogui.moveTo(second.x, second.y) pyautogui.dragTo(final.x, final.y, duration = 0.7)
def Trash(): exitTrash = pyautogui.Point(x=330, y=91) Use() init = pyautogui.Point(x=900, y=297) final = pyautogui.Point(x=911, y=515) pyautogui.moveTo(init.x, init.y) pyautogui.mouseDown() pyautogui.moveTo(final.x, final.y, duration=0.1) time.sleep(1.4) pyautogui.mouseUp()
def test__normalizeXYArgs(self): self.assertEqual(pyautogui._normalizeXYArgs(1, 2), pyautogui.Point(x=1, y=2)) self.assertEqual(pyautogui._normalizeXYArgs((1, 2), None), pyautogui.Point(x=1, y=2)) self.assertEqual(pyautogui._normalizeXYArgs([1, 2], None), pyautogui.Point(x=1, y=2)) pyautogui.useImageNotFoundException() with self.assertRaises(pyautogui.ImageNotFoundException): pyautogui._normalizeXYArgs("100x100blueimage.png", None) pyautogui.useImageNotFoundException(False) self.assertEqual(pyautogui._normalizeXYArgs("100x100blueimage.png", None), None)
def reportAPlayer(self, leagueRegion, point): # move directly to the report button reportPoint = pyautogui.Point(leagueRegion[0] + point.x, leagueRegion[1] + point.y + 20) self.logger.info("move mouse to report button: %s", reportPoint) pyautogui.moveTo(reportPoint) pyautogui.mouseDown(reportPoint, button='left', duration=1.0) pyautogui.mouseUp(reportPoint, button='left') time.sleep(0.3) self.logger.info("locate check boxes") # locate report check boxes checkboxes = list(pyautogui.locateAllOnScreen(self.images.checkbox, region=leagueRegion, confidence=0.7)) if checkboxes: # get random numbers rn = myRandom() # click check boxes for i in rn: pyautogui.click(checkboxes[i]) # paste report text to comment text field commentTextField = pyautogui.locateCenterOnScreen(self.images.commentText, region=leagueRegion) if commentTextField: pyautogui.click(commentTextField) pyperclip.copy(self.reportText) pyautogui.hotkey('ctrl','v') # cancel report for testing # cancel = pyautogui.Point(self.cancel_1280_720.x + leagueRegion[0], self.cancel_1280_720.y + leagueRegion[1]) # self.logger.info(cancel) # if cancel: # pyautogui.click(cancel) # return #press report confirm button reportConfirmRetry = 3 while reportConfirmRetry > 0: reportConfirm = pyautogui.locateCenterOnScreen(self.images.reportConfirm, region=leagueRegion) if reportConfirm: pyautogui.moveTo(reportConfirm) pyautogui.click(reportConfirm) break else: self.logger.debug("report confirm button not found, wait for 1 second to retry. %d left" % reportConfirmRetry) reportConfirmRetry = reportConfirmRetry - 1 time.sleep(1) pass else: self.logger.info('checkbox is not detected') # cancel report and go on. cancel = pyautogui.Point(self.cancel_1280_720.x + leagueRegion[0], self.cancel_1280_720.y + leagueRegion[1]) pyautogui.click(cancel)
def startTheScript(self): count = 0 while True: time.sleep(0.5) count += 1 if not self.isRunning: print("pause") while not self.isRunning: one = 1 if (self.areWeInMainScreen()): self.goToPixAndClick(playButtonPixelPos) print("We are in MainScreen") if (self.areWeInBetweenMatchScreen()): time.sleep(self.timeBeforeConcede) self.goToPixAndClick(inBetweenSettingsButtonPixelPos1) print("We are in Between Matches") if (self.areWeInConcedeMenu()): self.goToPixAndClick(concedeButtonPos) print("We are in Concede Menu") if (self.areWeInMatchScreen()): time.sleep(self.timeBeforeConcede) self.goToPixAndClick(inBetweenSettingsButtonPixelPos1) print("We are in Match Screen") if count > 15: self.goToPixAndClick(pyautogui.Point(x=10, y=10)) count = 0
def Cycles(): Use() circelToButtonDiffY = 218 - 183 circelToButtonDiffX = 876 - 574 diffY = 375 - 183 init = pyautogui.Point(574, 183) count = 0 while 1: r,g,b = pyautogui.pixel(init.x,init.y) if r in range(100) and b in range(100) and b in range(100): pyautogui.click(init.x + circelToButtonDiffX, init.y + circelToButtonDiffY) print('bingo') init = pyautogui.Point(init.x, init.y + diffY) count +=1 if count == 3: break
def generate_random_map(): pyautogui.click(x=25, y=18) default_terrain_dropdown = pyautogui.locateCenterOnScreen( "images/hd/map-editor/aoe2-map-editor-default-terrain-text.png") default_terrain_dropdown_clickable = pyautogui.Point( default_terrain_dropdown.x + 195, default_terrain_dropdown.y + 20) pyautogui.click(default_terrain_dropdown_clickable) terrain_index = round(random.uniform(0, len(terrain_dict)) - 1) pyautogui.typewrite(list(terrain_dict[terrain_index].values())[0], interval=0.2) generate_map_button_center = pyautogui.locateCenterOnScreen( "images/hd/map-editor/aoe2-generate-map-button.png") pyautogui.click(generate_map_button_center)
def maybe_slightly_perturbate(self): ''' perturbate location, but ensure it stays within a margin for error of the original location ''' if random.random() >= CHANCE_TO_PERTURBATE_LOCATION: return print("Perturbating location...") original_x = self.original_location.x original_y = self.original_location.y lower_bound_x = original_x - self.MARGIN_FOR_ERROR_PX upper_bound_x = original_x + self.MARGIN_FOR_ERROR_PX new_x = random.randint(lower_bound_x, upper_bound_x) lower_bound_y = original_y - self.MARGIN_FOR_ERROR_PX upper_bound_y = original_y + self.MARGIN_FOR_ERROR_PX new_y = random.randint(lower_bound_y, upper_bound_y) self.current_location = pyautogui.Point(new_x, new_y)
import pyautogui import pyscreeze import time import configparser import datetime import PyWinMouse pyautogui.PAUSE = 0.2 pyautogui.FAILSAFE = False #on set up la config config = configparser.ConfigParser() config.read("config.ini") playButtonPixelPos = pyautogui.Point( x=eval(config["DEFAULT"]["playButtonPixelPos"])[0], y=eval(config["DEFAULT"]["playButtonPixelPos"])[1]) playButtonPixelRGB = eval(config["DEFAULT"]["playButtonPixelRGB"]) inBetweenSettingsButtonPixelPos1 = pyautogui.Point( x=eval(config["DEFAULT"]["inBetweenSettingsButtonPixelPos1"])[0], y=eval(config["DEFAULT"]["inBetweenSettingsButtonPixelPos1"])[1]) inBetweenSettingsButtonPixelRGB1 = eval( config["DEFAULT"]["inBetweenSettingsButtonPixelRGB1"]) inBetweenSettingsButtonPixelPos2 = pyautogui.Point( x=eval(config["DEFAULT"]["inBetweenSettingsButtonPixelPos2"])[0], y=eval(config["DEFAULT"]["inBetweenSettingsButtonPixelPos2"])[1]) inBetweenSettingsButtonPixelRGB2 = eval( config["DEFAULT"]["inBetweenSettingsButtonPixelRGB2"]) concedeButtonPos = pyautogui.Point( x=eval(config["DEFAULT"]["concedeButtonPos"])[0], y=eval(config["DEFAULT"]["concedeButtonPos"])[1])
import pyautogui as pag import time speaker = pag.Point(206, 1045) reset = pag.Point(210, 874) reset2 = pag.Point(210, 844) string = ['Chrome','VLC media player','Word','Microsoft Teams', 'Reader DC','Zoom Webinar'] site = string[-1] tw = pag.getWindowsWithTitle(site) tw[0].maximize() while True: tw[0].activate() init = pag.position() pag.moveTo(speaker, duration = 0.2) pag.leftClick(speaker) pag.moveTo(reset, duration = 0.2) pag.leftClick(reset) pag.moveTo(speaker, duration = 0.2) pag.leftClick(speaker) pag.moveTo(reset2, duration = 0.2) pag.leftClick(reset2)
import pyautogui,time time.sleep(5) point = pyautogui.Point(1000,750) pyautogui.moveTo(point, duration=0.25) while True: time.sleep(3*60) pyautogui.click(1000,750)
return (loc) def copy_clipboard(): time.sleep( .01) # ctrl-c is usually very fast but your program may execute faster pyautogui.hotkey('ctrl', 'c') time.sleep( .01) # ctrl-c is usually very fast but your program may execute faster return pyperclip.paste() sleep(5) first_item = (76, 357) locs = { 'summary_loc': pyautogui.Point(x=1003, y=206), 'company_loc': Point(x=1069, y=205), 'window_body': Point(x=1628, y=460), 'Drag_start': Point(x=1592, y=999), 'Drag_end': Point(x=969, y=255), 'end_scroll_loc': Point(1910, 979) } pyautogui.click(first_item, duration=0.15, tween=pyautogui.easeInOutQuad) summary_loc = locs['summary_loc'] window_body = locs['window_body'] company_loc = locs['company_loc'] Drag_start = locs['Drag_start'] Drag_end = locs['Drag_end'] end_scroll_loc = locs['end_scroll_loc']
def Use(): use = pyautogui.Point(x=1273, y=658) pyautogui.click(use.x, use.y) time.sleep(1)
def generate_random_point() -> pyautogui.Point: random_x = random.uniform(12, 140) + 400 random_y = random.uniform(60, 200) + 272 return pyautogui.Point(random_x, random_y)
import pyautogui import numpy as np from PIL import Image from io import BytesIO import win32clipboard import time import winsound QUESTION_STR_LIMIT = 255 QUESTION_LINE_LIMIT = 40 # screen size dependent constants MAIN_INP_POS = pyautogui.Point(1942, 1376) MAIN_INP_HIGHER_POS = pyautogui.Point(2010, 1330) CREATE_A_QUESTION_BTN = pyautogui.Point(2043, 1366) CREATE_THE_QUESTION_BTN = pyautogui.Point(2043, 1366) QUESTION_OPTION_HEIGHT = 40 QUESTION_LINE_HEIGHT = 10 QUESTION_TOP_LEFT = pyautogui.Point(4, 170) SLEEP_DUR = 0.5 solution_start_height = -1 def get_question_size_offset(question_str): s = len(question_str) if s > QUESTION_LINE_HEIGHT * 3: return QUESTION_LINE_HEIGHT * 2 return (s // QUESTION_LINE_LIMIT) * QUESTION_LINE_HEIGHT
def subp(p1, p2): return pyautogui.Point(x=p1.x - p2.x, y=p1.y - p2.y)
def __init__(self, logger, images, cwd): self.logger = logger self.images = images with open(os.path.join(cwd, 'reportText.txt'), encoding='utf8') as file: self.reportText = file.read() self.cancel_1280_720 = pyautogui.Point(820, 88) self.team_1280_720 = [ pyautogui.Point(280, 150), pyautogui.Point(280, 190), pyautogui.Point(280, 230), pyautogui.Point(280, 270), pyautogui.Point(280, 310), ] self.enemy_1280_720 = [ pyautogui.Point(280, 395), pyautogui.Point(280, 435), pyautogui.Point(280, 475), pyautogui.Point(280, 515), pyautogui.Point(280, 555), ]
import pyautogui, time while True: time.sleep(5 * 60) nowPosition = pyautogui.position() print(nowPosition) x, y = nowPosition.x, nowPosition.y newPosition = pyautogui.Point(x + 1, y + 1) pyautogui.moveTo(newPosition, duration=0.25)
def addp(p1, p2): return pyautogui.Point(x=p1.x + p2.x, y=p1.y + p2.y)
def Download(): time.sleep(1) Use() init = pyautogui.Point(x=677, y=467) pyautogui.click(init.x, init.y)
class Color(enum.Enum): black = 1 dark = 2 light = 3 red = 4 orange = 5 olive = 6 green = 7 blue = 8 purple = 9 pen_colors = { Color.black: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(1)), Color.dark: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(2)), Color.light: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(3)), Color.red: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(4)), Color.orange: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(5)), Color.olive: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(6)), Color.green: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(7)), Color.blue: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(8)), Color.purple: pyautogui.Point(x=tools_pen_pos_x(2), y=tools_pen_pos_y(9)), } pen_size = { 1: pyautogui.Point(x=tools_pen_pos_x(3), y=tools_pen_pos_y(1)), 2: pyautogui.Point(x=tools_pen_pos_x(3), y=tools_pen_pos_y(2)), 3: pyautogui.Point(x=tools_pen_pos_x(3), y=tools_pen_pos_y(3)), 4: pyautogui.Point(x=tools_pen_pos_x(3), y=tools_pen_pos_y(4)),
def set_coords(): #Sets coordinates for the necessary points on screen. coords ={0:['browser address bar'], 1:['"more" button on the bottom of the People page'], 2:['gray background to the left of any user photo on the People page'], 3:['"AT" letters of the "CHAT" button on the profile page of any user that - TAKE NOTE - \n1) has NO background photo; \n2) is NOT among your favourite users'], 4:['"AT" letters of the "CHAT" button on the profile page of any user that - TAKE NOTE - \n1) HAS a background photo; \n2) is NOT among your favourite users'], 5:['"SEND" button in the message window of any user'], 6:['"BACK" button of the browser']} gui.alert(text='First I need to gather coordinates for certain points on your screen.', title='Pyster - automatic poster') for i in range(0, 7): gui.confirm('Press OK, set the mouse cursor on the'+str(coords[i][0])+ ', wait till you hear a beep and come back here.', title='Pyster - automatic poster') time.sleep(5) coords[i]=gui.position() winsound.Beep(frequency=500, duration=500) gui.alert('Coords set!'+str(coords), title='Pyster - automatic poster') with open('coords.csv', 'w') as f: for key in coords.keys(): f.write("%s;%s;%s\n"%(key,coords[key][0],coords[key][1])) return coords def scrape_dict(users=250): '''Scrape a given number of users from the portal. argument: number of users to be scraped returns: a dict with usernames as keys and current datetime as values. REFACTOR IT TO A LIST! dict is unnecessary. ''' user_dict = dict() pages = int(users/50) for _ in range(0, pages): for _ in range(0, 23): gui.press('pgdn') gui.moveTo(coords[1]) gui.click() time.sleep(1) gui.moveTo(coords[2]) gui.keyDown('ctrl') gui.press('a') clip.copy('') gui.press('c') gui.keyUp('ctrl') a = clip.paste() b = a.split('FAVOURITES')[1] c = b.split('\r\nLOCATION')[0] d = c.split('\r\n\r\n') len(d) for e in d: f = e.split('\r\n')[0] user_dict[f] = datetime.datetime.today() return user_dict def get_user_batch(user_input): #Scrape the desired number of users among those not recently messaged. REFACTOR - see scrape_dict() user_count = user_input mid_dict = {} last_dict = {} gui.alert('Enter the "People" tab and filter out the users as you like.\nReturn here, press OK, switch to the portal page an click the gray background. \nWait for the beep', title='Pyster - automatic poster') time.sleep(5) while (len(mid_dict) < user_input) and (user_count < 3500): temp_dict = scrape_dict(users=user_count) for key, value in temp_dict.items(): if (key not in main_dict) or ((value-main_dict[key]) > datetime.timedelta(days=14)): mid_dict[key] = datetime.datetime(2009, 7, 28, 7, 25, 58, 913124) else: pass if (last_dict == mid_dict): user_count = 3501 user_count = user_count*2 last_dict = mid_dict new_dict = {} keys = [*mid_dict][0:user_input] for key in keys: new_dict[key] = mid_dict[key] winsound.Beep(frequency=500, duration=500) return new_dict def send_msg(user, msg): #Send msg to user, update main_dict. time.sleep(5) gui.moveTo(coords[0]) gui.click() gui.typewrite('[portal address]'+str(user)) gui.press('enter') gui.moveTo(coords[4]) time.sleep(1) gui.click() time.sleep(1) gui.typewrite(str(msg)) time.sleep(1) gui.moveTo(coords[5]) time.sleep(1) #gui.click() time.sleep(1) gui.moveTo(coords[3]) time.sleep(1) gui.click() time.sleep(1) gui.typewrite(str(msg)) time.sleep(1) gui.moveTo(coords[5]) time.sleep(1) #gui.click() main_dict[user] = datetime.datetime.today() def backup(): # Writes the current state of main_dict to CSV file with open('main_dict.csv', 'w') as f: for key in main_dict.keys(): f.write("%s,%s\n"%(key,main_dict[key])) if len(coords)>1: #Program core try: main_dict= {} with open('main_dict.csv', newline='') as f: reader = csv.reader(f) for row in reader: main_dict[row[0]] = datetime.datetime.strptime(row[1],"%Y-%m-%d %H:%M:%S.%f") coords = {} try: with open('coords.csv', newline='') as f: reader = csv.reader(f, delimiter=';') for row in reader: coords[int(row[0])] = gui.Point(row[1],row[2]) except: coords = set_coords() user_input = int(gui.prompt('How many users do you want to message?', title='Pyster - automatic poster')) new_dict = get_user_batch(user_input) msg = str(gui.prompt('What message do you want to send?\nEnter the text below, click "OK" and wait a while.', title='Pyster - automatic poster')) for key,value in new_dict.items(): send_msg(key,msg) winsound.Beep(frequency=500, duration=500) gui.alert('The message "'+msg+'" was succesfully sent to '+str(len(new_dict))+' users.', title='Pyster - automatic poster') backup() finally: backup()