def rebirth(time_before_rebirth, time_start): rebirth_time = time.time() - time_start # print(time.strftime('%M Minutes and %S seconds.', time.struct_time(time.gmtime(rebirth_time)))) if rebirth_time > time_before_rebirth: global rebirths pyautogui.click(game_region[0] + 100, game_region[1] + 525, clicks=2, pause=1, interval=0.25) pyautogui.click(game_region[0] + 675, game_region[1] + 650, clicks=2, pause=1, interval=0.25) pyautogui.click(game_region[0] + 540, game_region[1] + 400, clicks=2, pause=1, interval=0.25) rebirths += 1 print('Total number of rebirths: ' + str(rebirths)) try: rebirth_yes = pyautogui.locateOnScreen("rebirth_yes.png") rebirth_yes_location = pyautogui.locateCenterOnScreen(rebirth_yes) pyautogui.leftClick(rebirth_yes_location[0], rebirth_yes_location[1]) # pyautogui.click(game_region[0] + 540, game_region[1] + 400, clicks=2, pause=1) except: pass setup()
def main(): global width global height global total_battles global last_player_pos global origin total_battles = read_current_battles() print("BOT STARTED WITH: " + str(total_battles) + " battles") position = read_player_pos() origin = position.copy() last_mouse_move = time() while(True): active_window = gui.getActiveWindow() if active_window != None and active_window.title == 'Temtem': if(time() > last_player_pos): last_player_pos = time() temp = read_player_pos() if temp != None: position = temp take_action() if last_mouse_move + random.randint(10,20) < time(): last_mouse_move = time() if(random.randint(0, 100) < 10): gui.moveTo(width/2 + random.randint(-500,200), random.randint(100,400), duration=(random.randint(1,2) * random.random())) gui.leftClick() else: print('TemTem not opened..') sleep(2)
def mapping_image(image, operation): box_location = auto.locateOnScreen(image) image_center = auto.center(box_location) if operation == "double_click": auto.doubleClick(image_center) else: auto.leftClick(image_center)
def moveToAndClick(pos, rightClick): pyautogui.moveTo(pos.x, pos.y) if rightClick is True: pyautogui.rightClick(pos.x, pos.y) else: pyautogui.leftClick(pos.x, pos.y)
def build(): from GUIParser import GUIParser center = pyautogui.size()[0] // 2, pyautogui.size()[1] // 2 # center = self.InGameGui.activeWindow.center pyautogui.moveTo(*center) errorMess_paths = [ fr"GameMessages/Other_objects_prevent_you_from_placing_this_here.PNG", fr"GameMessages/You_must_explore_this_area_before_placing_items_there.PNG", fr"GameMessages/This_building_has_corps_around_it_You_need_to_allow_more_space.PNG", fr"GameMessages/You_may_not_obstruct_a_Trade_Route.PNG" ] search = AoE3Env.PerformCrossSearch(errorMess_paths, func=pyautogui.leftClick, sleep=0.7, inv=True) if search is not None: return None while any([GUIParser.imgIn(mess) for mess in errorMess_paths]): direction: str = util.randomDirection( ("left", "right", "up", "down")) pyautogui.keyDown(direction) util.randomSleep(b=0.2) pyautogui.keyUp(direction) pyautogui.press(direction) pyautogui.leftClick() pyautogui.hotkey("esc")
def mouse_click(point, operation_type): if operation_type == MouseOperationEnum.single_click: auto.leftClick(point[0], point[1]) if operation_type == MouseOperationEnum.double_click: auto.double_click(point[0], point[1]) if operation_type == MouseOperationEnum.right_click: auto.right_click(point[0], point[1])
def click_plus(quantity, itemURL, failed): if failed == True: return True try: x1, y1 = gui.locateCenterOnScreen("plus.png", grayscale=False, confidence=.7, region=(0, 0, 1500, 1000)) gui.click(x=x1, y=y1, button='left', clicks=(quantity - 1), interval=.125) except: logging.error("Plus-Button-Missing: \n" + itemURL + "\n" + str(quantity)) return True try: gui.moveRel(100, 100, duration=.125) gui.leftClick() x1, y1 = gui.locateCenterOnScreen("plus.png", grayscale=False, confidence=.7, region=(0, 0, 1500, 1000)) except: logging.error("Possible-Quantity-Wrong: \n" + itemURL + "\n" + str(quantity)) return True
def _click_at_with_random(sg, x_offset, y_offset): minRand = 1 maxRand = 10 randx = random.randint(minRand, maxRand) randy = random.randint(minRand, maxRand) pyautogui.leftClick(sg.x + x_offset + randx, sg.y + y_offset + randy)
def login(self): start = datetime.utcnow() print("login start:", start) point = ag.locateCenterOnScreen(self.arpe_icon, confidence=self.conf) if point is not None: print("open popup auto refresh plus:", datetime.utcnow() - start) ag.leftClick(point.x, point.y) sleep(1) point = ag.locateCenterOnScreen(self.arpe_stop, confidence=self.conf) if point is not None: print("press stop auto refresh plus:", datetime.utcnow() - start) ag.leftClick(point.x, point.y) point = ag.locateCenterOnScreen(self.yukon_icon, confidence=self.conf) if point is not None: print("open popup yukon:", datetime.utcnow() - start) self.login_success.emit() ag.leftClick(point.x, point.y) sleep(1) print("paste password yukon:", datetime.utcnow() - start) passwd = keyring.get_password(*self.log_data) self.cb.setText(passwd) ag.leftClick(518, 228) ag.hotkey('ctrl', 'shift', 'v', interval=0.25) self.cb.setText('') point = ag.locateCenterOnScreen(self.login_btn, confidence=self.conf) if point is not None: ag.leftClick(point, interval=0.25) print(datetime.utcnow() - start)
def restartGame(self): os.system("open "+self.launcher_path+" --args "+self.args) time.sleep(10) coords = pyautogui.locateOnScreen(self.start_button_img) x,y=pyautogui.center(coords) pyautogui.leftClick(x/2,y/2) print("游戏重启完成")
def mapping_img(self, img, click): box_location = pyautogui.locateOnScreen(img) center = pyautogui.center(box_location) if click == 'double': pyautogui.doubleClick(center) else: pyautogui.leftClick(center)
def make_action(position_x, position_y, action): # making array out of action - encoder require it for proper decoding action_array = [action] print(action_array) # decoding action coded in int by encoder to string of corresponding action action = encoder.decode(action_array) action = action.lower() if position_x or position_y == 0: position_x, position_y = 1, 1 # moving mouse to position of action pyautogui.moveTo(position_x, position_y) # regarding action which has to be made if action == 'move': pass elif action == 'left': pyautogui.leftClick() elif action == 'right': pyautogui.rightClick() elif action == 'middle': pyautogui.middleClick() elif 'bind' in action: number = action[-1] pyautogui.hotkey('shift', number) elif 'add' in action: number = action[-1] pyautogui.hotkey('ctrl', number) else: pyautogui.keyDown(action) time.sleep(2) pyautogui.keyUp(action) print('Action {} will be made on X-coordinate {} and Y-coordinate {}'.format(action, position_x, position_x))
def openchrome(): pg.leftClick(103,1045,.2,.12) pg.typewrite('Google Chrome') time.sleep(1) pg.hotkey('enter') time.sleep(1) return
def locate_image_and_click(image, confidence=0.5, iter=5): while is_image_on_screen(image, confidence) is False: logger.info('Locating ' + os.path.basename(image) + '...') # time.sleep(1) pyautogui.moveTo(pyautogui.locateCenterOnScreen(image)) logger.info(os.path.basename(image) + ' found!') pyautogui.leftClick()
def begin_pan(distance): ag.rightClick() # arbitrary confidence threshold x, y = ag.locateCenterOnScreen('pan.png', confidence=.5) ag.leftClick(x, y) ag.drag(distance, 0, duration=.1) ag.drag(-distance, 0, duration=.1)
def sparringPit_click_upgrade_buttons(): while this_is_on_screen("sparringPit_note_levelReady"): level_ready_coordinates = get_image_coordinates( "sparringPit_note_levelReady") ptg.leftClick(level_ready_coordinates[0] + 250, level_ready_coordinates[1] + 650) time.sleep(1)
def nextStep(imgName): coords = pyautogui.locateCenterOnScreen(imgName) while coords is None: coords = pyautogui.locateCenterOnScreen(imgName) if coords is None: print('Nie znaleziono koordynatow!') pyautogui.leftClick(coords.x, coords.y)
def select_stress_test(): side_bar_stress_test_image = [stress_test_image_path['stress_unselected'], \ stress_test_image_path['stress_selected']] for image in side_bar_stress_test_image: if pyautogui.locateOnScreen(image,confidence=0.5, grayscale=True) is not None: pyautogui.moveTo(pyautogui.locateCenterOnScreen(image)) pyautogui.leftClick()
def find_next_week(): for x in range(280, 605, 30): for y in range(320, 565, 30): color_match = pyautogui.pixelMatchesColor(x, y, (255, 219, 153)) if color_match: pyautogui.leftClick(x + 30, y + 30) return x, y
def __testMouseMove(self, counter): """ ユニットテスト用の関数。無視でいいです。 Parameters ---------- counter : int 何回目のクリックか示す """ x_from, y_from, x_to, y_to = self.__getFromAndTo(counter) x_mid = int((x_from + x_to) / 2) y_mid = int((y_from + y_to) / 2) if i == 1: pygame.mouse.set_pos(x_from, y_from) pygame.time.wait(100) elif i == 2: pygame.mouse.set_pos(x_mid, y_mid) pygame.time.wait(100) elif i == 3: pygame.mouse.set_pos(x_mid, y_mid) pygame.time.wait(100) elif i == 4: pygame.mouse.set_pos(x_to, y_to) pygame.time.wait(100) else: x, y = pag.position() pag.leftClick(x, y)
def enter_name_password_and_apply(self, mainN, PASS): self.wait_and_click('assets\open_1c\SName_indicator.png') pg.press('down') pg.move(0, 25) a = pg.locateCenterOnScreen(mainN, confidence=0.9) while a == None: pg.scroll(-450) a = pg.locateCenterOnScreen(mainN, confidence=0.9) pg.leftClick(a) self.wait_and_click('assets\open_1c\pass_indicator.png') pg.typewrite(PASS) self.wait_and_click('assets\open_1c\onec_enter_apply.png') time.sleep(2) passs = pg.locateCenterOnScreen('assets\open_1c\wrongpass.png', confidence=0.9) if passs != None: self.wait_and_click('assets\open_1c\wrongpassok.png')
def run(self): self.running = True self.int = self.delay.get() while self.running: pyautogui.leftClick() time.sleep(self.int) self.var.set(self.var.get() + 1)
def open_shift(self, mainN, shopN, PASS, tst=False): self.open_1c(mainN, PASS) while pg.locateCenterOnScreen('assets\open_shift\shift.png', confidence=0.9) == None: self.wait_and_click('assets\open_shift\sells.png') self.wait_and_click('assets\open_shift\shift.png') open = pg.locateCenterOnScreen( 'assets\open_shift\shifts_indicator.png', confidence=0.9) while open == None: open = pg.locateCenterOnScreen( 'assets\open_shift\shifts_indicator.png', confidence=0.9) pg.leftClick( pg.locateCenterOnScreen('assets\open_shift\cashbox.png', confidence=0.9)) cashbox = pg.locateCenterOnScreen(shopN, confidence=0.9) while cashbox == None: pg.press('down') cashbox = pg.locateCenterOnScreen(shopN, confidence=0.9) pg.leftClick(cashbox) # открыть смену if tst == False: self.wait_and_click('assets\open_shift\open_shift_btn.png') # закрыть окно self.wait_and_click('assets\open_shift\shift_close_window.png')
def registration(self, mainN, regN, PASS, tst=False): self.open_1c(mainN, PASS) self.make_full_win() self.wait_and_click('assets\Reg\Reg.png') self.wait_and_click('assets\Reg\Reg_indicator.png') pg.press('down') pg.move(0, 20) a = pg.locateCenterOnScreen(regN, confidence=0.8) while a == None: pg.scroll(-350) a = pg.locateCenterOnScreen(regN, confidence=0.8) pg.leftClick(a) self.wait_and_click('assets\Reg\Reg_pass_ind.png') pg.typewrite(PASS) if tst == True: self.wait_and_click('assets\Reg\Reg_close.png') else: self.wait_and_click('assets\Reg\Reg_apply_start.png') self.wait_and_click('assets\Reg\Reg_apply_yes.png') self.wait_and_click('assets\Reg\Reg_apply_ok.png')
def openvideo(): pg.leftClick(180, 70, .2, .12) pg.typewrite('C:\\Users\\YOUR_USERNAME\\Desktop\\Video') pg.hotkey('enter') time.sleep(.5) pg.moveTo(380, 310, .12) pg.doubleClick() return
def startAutoClicking(): running = True time.sleep(1) while running == True: if keyboard.is_pressed("B"): running = False break pyautogui.leftClick(pyautogui.position())
def enterdesc(): pg.hotkey('space') pg.typewrite('CHANGE_ME') pg.leftClick(335, 675, .2, .12) pg.typewrite('CHANGE_ME') pg.moveTo(1670, 450, .12) pg.dragTo(1670, 640, .5) return
def left_click(path): #定义一个函数实现左键点击的功能 left_click1 = pyautogui.locateOnScreen(path) #把目标图片当作参数传递给path print('left_click1::', left_click1) if left_click1: url_x, url_y = pyautogui.center(left_click1) pyautogui.leftClick(url_x, url_y) return True return False
def exchange(self, mainN, PASS, tst=False): MANUAL = False self.open_1c(mainN, PASS) self.wait_and_click('assets\ex\exchange1.png') self.wait_and_click('assets\ex\exchange2.png') done = pg.locateCenterOnScreen('assets\ex\exchange_done.png', confidence=0.9) while done == None: done = pg.locateCenterOnScreen('assets\ex\exchange_done.png', confidence=0.9) time.sleep(5) if pg.locateCenterOnScreen('assets\ex\exchange_manual.png', confidence=0.9) != None: MANUAL = True if MANUAL == False: # if pg.locateCenterOnScreen('assets\ex\exchange_failed.png', confidence=0.9) == None: # ex1 = '+' # else: # ex1 = '-' # if pg.locateCenterOnScreen('assets\ex\exchange_success.png', confidence=0.9) != None: # ex2 = '+' # else: # ex2 = '-' self.wait_and_click('assets\ex\exchange_ok.png') self.wait_and_click('assets\ex\exchange_close.png') self.wait_and_click('assets\ex\Alert_message_close.png') exchange_res = '+++' else: self.wait_and_click('assets\ex\exchange_manual_yes.png') self.wait_and_click('assets\ex\exchange_manual_enter_pass.png') pg.typewrite(PASS) self.wait_and_click('assets\ex\exchange_manual_pass_apply.png') ex_man = pg.locateCenterOnScreen( 'assets\ex\exchange_manual_done_ind.png', confidence=0.9) while ex_man == None: ex_man = pg.locateCenterOnScreen( 'assets\ex\exchange_manual_done_ind.png', confidence=0.9) ex_close = pg.locateCenterOnScreen( 'assets\ex\exchange_manual_close_alert.png', confidence=0.9) while ex_close != None: pg.leftClick(ex_close) exchange_res = '+++' self.send_exchange_result(exchange_res, tst)
def get_screenshot(path, i): pyautogui.hotkey('f5') sleep(5) checkbox = pyautogui.position(x=516, y=212) pyautogui.leftClick(checkbox) sleep(5) image = autopy.bitmap.capture_screen() image.save(path)