def generate_quiz(start: int, end: int): """ This function generates quiz templates for Dynalist for learning Java. I have a book with many quiz questions and I like it. I want to keep track of my answers in Dynalist. This template allows me to answer the questions with using ony the mouse. ^-^ :param start: starting number :param end: finishing number :return: """ pyautogui.sleep(7) for num in range(start, end+1): # input current number pyautogui.typewrite(str(num), interval=0.1) # next line and indent pyautogui.typewrite(["enter", "tab"], interval=0.1) pyautogui.typewrite("yay nay", interval=0.1) # make checked by ctrl+shift+c pyautogui.hotkey("ctrl", "shift", "c") pyautogui.typewrite(["enter", "tab", *list("yay"), "enter", *list("nay"), "enter", "A", "enter", "B", "enter", "C", "enter", "D" ], interval=0.1) # go back to base level pyautogui.typewrite(["enter"], interval=0.1) pyautogui.hotkey("shift", "tab") pyautogui.hotkey("shift", "tab")
def fn_skypeCallProcess(address): uri = 'skype:' + address webbrowser.open(uri, new=2) pyautogui.sleep(5) pyautogui.click(700, 550) pyautogui.click(700, 505)
def move_ship(self): global MOVE_TO pag.press('m', presses=1, interval=0.25) pag.sleep(1.5) if not MOVE_TO: map_image = get_map_image() self_loc = search_template(map_image, 'map_self_icon.bmp') print('self_loc', self_loc) if self_loc: MOVE_TO = (settings.BATTLE_MAP_TOPLEFT[0] + settings.BATTLE_MAP_SIZE[0] - self_loc[1], settings.BATTLE_MAP_TOPLEFT[1] + settings.BATTLE_MAP_SIZE[1] - self_loc[0]) else: MOVE_TO = (settings.BATTLE_MAP_TOPLEFT[0] + settings.BATTLE_MAP_SIZE[0] / 2, settings.BATTLE_MAP_TOPLEFT[1] + settings.BATTLE_MAP_SIZE[1] / 2) for i in range(4): loc = (MOVE_TO[0] + randint(-50, 50), MOVE_TO[1] + randint(-50, 50)) pag.moveTo(loc) pag.click(clicks=2, interval=0.5, button='left') time.sleep(1) pag.press('esc') time.sleep(2)
def exec(): with open("log02.txt", "w") as file: p.hotkey('win', 'r') p.sleep(0.5) p.write('notepad') p.press('enter') p.sleep(0.5) p.write('Testestwsztst') p.hotkey('alt', 'f4') p.press('enter') file.write("--- Salvando...") p.sleep(1) janela = p.getActiveWindow() janela.maximize() Atual = p.locateOnScreen(r"C:\dev\RPA-Foms\desktop.png", confidence=0.8) pesqAtual = p.center(Atual) xAtal, yAtual = pesqAtual p.click(xAtal, yAtual) p.sleep(0.5) Input = p.locateOnScreen(r"C:\dev\RPA-Foms\input.png", confidence=0.8) pesqInput = p.center(Input) xInput, yInput = pesqInput p.click(xInput, yInput) p.sleep(0.5) file.write("--- Escrevendo...") p.write('teste') p.press('enter') file.close()
def RepeatAcceptMatch(): x = 0 while (x < 25): pg.moveTo(1000, 700) # accept match pg.click() x = x + 1 pg.sleep(1)
def getmessage(): p.moveTo(535, 621) p.tripleClick() p.sleep(0.5) p.hotkey('ctrl', 'c', interval=0.1) p.sleep(0.1) return (pyperclip.paste())
def check_power_option_in_desktop_and_start_menu(self, user_mode, power_option_desktop, power_option_start, postfix): self.switch_user(user_mode) self.right_click_desktop() time.sleep(1) power_desktop = self.wait_pictures(power_option_desktop) if not power_desktop: pyautogui.screenshot(self.img_path + 'power_option_desktop_{}.png'.format(postfix)) time.sleep(1) pyautogui.hotkey('esc') pyautogui.sleep(1) pyautogui.hotkey('ctrl', 'alt', 's') pyautogui.sleep(1) power_start = self.wait_pictures(power_option_start) if not power_start: pyautogui.screenshot(self.img_path + 'power_option_start_{}.png'.format(postfix)) time.sleep(1) time.sleep(1) pyautogui.press('esc') time.sleep(1) return power_desktop, power_start
def hotkey(image, reg, button1, button2): while True: image_location = gui.locateOnScreen(image, region=reg) if image_location is not None: gui.hotkey(button1, button2) gui.sleep(0.1) break
def fire_ship(self): # if not pag.pixelMatchesColor(*settings.AUTO_PILOT, # (76, 232, 170), # tolerance=30): # self.move_ship() pag.press('`', presses=1, interval=0.25) pag.press('r', presses=1, interval=0.25) enemy_locs = self.select_enemy() # print(nearest_enemy_loc) if not enemy_locs: pag.sleep(5) return for dis in sorted(enemy_locs.keys()): loc = enemy_locs[dis] if self.try_fire(loc): break if not self.FIRE_ROUNDS % 10: # print(f'#{FIRE_ROUNDS} use consuption') pag.press('t', presses=1, interval=0.25) pag.press('y', presses=1, interval=0.25) pag.press('u', presses=1, interval=0.25) pag.sleep(1) self.FIRE_ROUNDS += 1
def get_images(): pyautogui.hotkey('alt', 'tab') pyautogui.sleep(1) for i in range(283, 1638): pyautogui.moveTo(i, 500) pyautogui.sleep(0.1) get_screenshot(f'{i}', 325, 988, 360, 1003)
def mouse_move(_yaw, _pitch): pre_x_pos = 872 pre_y_pos = -720 temp_x_pos = 872 temp_y_pos = -720 pyautogui.sleep(2) pyautogui.moveTo(872, -720, duration=0.0) #初期位置 while True: # 角度から座標への変換 x_pos, y_pos = angle_to_pos(_yaw.value, _pitch.value) # ローパスフィルタ x_pos = pre_x_pos * 0.5 + x_pos * (1 - 0.5) y_pos = pre_y_pos * 0.5 + y_pos * (1 - 0.5) pre_x_pos = x_pos pre_y_pos = y_pos #print(x_pos, y_pos) #pitchを+60度または-60度以上にすることで自動操作解除 if abs(_pitch.value) < 60: ### 以下,youtube用 pyautogui.mouseDown() pyautogui.moveTo(x_pos, y_pos, duration=0.0) ### 以下,matterport用 #if len_point((x_pos-temp_x_pos), (y_pos-temp_y_pos)) > 100: # pyautogui.dragTo(x_pos, y_pos, duration=0.5) # temp_x_pos = x_pos # temp_y_pos = y_pos else: pyautogui.mouseUp()
def _new_mode(self): for transaction in gui.getAllTitles(): if transaction.startswith('ZLPC'): continue elif transaction.startswith(titles_tuple): temp_transaction = gui.getWindowsWithTitle(str(transaction))[0] temp_transaction.activate() print(temp_transaction) hotkey(transaction_names['new_mode'], (410, 30, 575, 60), 'ctrl', 'n') while gui.getActiveWindowTitle == temp_transaction: print(gui.getActiveWindowTitle) gui.sleep(0.25) print('test') if 'Information' in gui.getAllTitles(): dialog = gui.confirm(text='Много окошек. Закрываю одно', title='Limit of tabs', buttons=['OK', 'Cancel']) if dialog == 'OK': information = gw.getWindowsWithTitle('Information')[ 0] # ЗАКРЫВАЕТ ВСЕ ОКНА print(information) gui.press('esc') print(temp_transaction) temp_transaction.close() continue else: exit() elif gui.locateOnScreen(transaction_names['sap_easy_access'], region=names_region): break
def add_eba_question(question_str, h, quiz_name, question_num, is_need2_download): if len(question_str) > QUESTION_STR_LIMIT: print('question str is more than LIMIT', QUESTION_STR_LIMIT) return click_2_show_answer() x, y, n = find_answer_from_screen(h) copy_solution_url(x, y, quiz_name, question_num, is_need2_download) click_2_show_answer() # click to first telegram chat on telegram desktop pyautogui.click(1400, 100) pyautogui.sleep(SLEEP_DUR) pyautogui.click(CREATE_A_QUESTION_BTN.x, CREATE_A_QUESTION_BTN.y) pyautogui.sleep(SLEEP_DUR * 2) pyautogui.write(question_str) pyautogui.press('enter') for ch in ['A', 'B', 'C', 'D', 'E']: pyautogui.write(ch) pyautogui.press('enter') add_expo_to_the_question() click_2_choice(n) generate_the_question()
def upgrade_to(self, org_lvl, t_lvl): if (org_lvl >= t_lvl): logging.warning(f'升级到{t_lvl}级,高于原级别{org_lvl},退出') return else: logging.info(f'将从{org_lvl}升级到{t_lvl}') th = 200 cfg = self.config["建设菜单"]["建筑中心"]["弹窗"]["滚动区域"]["弹窗"]["升级按钮"]["矩形"] cfg_rect = self.config["建设菜单"]["建筑中心"]["弹窗"]["滚动区域"]["弹窗"]["等级区"]["矩形"] bak_pause = pyautogui.PAUSE pyautogui.PAUSE = 0.15 for _ in range(t_lvl - org_lvl): self.win.click(cfg[:2]) pyautogui.PAUSE = bak_pause pyautogui.sleep(bak_pause) for _ in range(t_lvl - org_lvl): img = self.win.screenshot(cfg_rect) level_code = self.win.gray_th_ocr(img, th=th, inv=True) level = self.bp.match_number(level_code) if (level >= t_lvl): break self.win.click(cfg[:2]) pyautogui.sleep(pyautogui.PAUSE) return level
def run_processes(): global processes processes.append(Process(400, 250, 400, 250, (75, 219, 106), 10)) while True: for p in processes: p.action() pag.sleep(10 / 1000)
def targetChecker(): mon = p.locateCenterOnScreen('mon.PNG', confidence=0.9) if not mon: t.sleep(0.2) p.keyDown('ctrl') t.sleep(0.2) p.keyDown('1') p.sleep(0.2) p.keyUp('ctrl') t.sleep(0.2) p.keyUp('14') t.sleep(4) p.hotkey('tab') try: target = p.locateCenterOnScreen('target.PNG', confidence=0.9) # 이미지를 통한 좌표 탐색 if target: attack() else: p.keyDown('d') t.sleep(0.5) p.keyUp('d') except: #p.hotkey('d') targetChecker()
def up_board_calibration(self): cur_cp = self.get_check_point() target_cp = "上边" if (cur_cp == target_cp): logging.debug(f"当前位置[{cur_cp},无需移动]") return logging.debug(f"校准开始:当前位置[{cur_cp}]") max_step = self.config["建设菜单"]["政策中心"]["弹窗"]["滚动区域"]["最大移动步长"] move_step = int(max_step * self.win.height + 0.5) backup_pause = pyautogui.PAUSE pyautogui.PAUSE = 0.1 last_move_dir = self.get_dir_from_current_point(cur_cp, target_cp) logging.debug(f"开始从[{cur_cp}]向[{target_cp}]移动,方向{last_move_dir}") while cur_cp != target_cp: move_dir = self.get_dir_from_current_point(cur_cp, target_cp) if (last_move_dir != move_dir): move_step = int(move_step / 2) move_step = 1 if move_step < 1 else move_step pyautogui.moveRel(0, move_dir * move_step) last_move_dir = move_dir logging.debug(f"从[{cur_cp}]向[{target_cp}]移动{move_dir*move_step}") cur_cp = self.get_check_point() pyautogui.PAUSE = backup_pause pyautogui.sleep(pyautogui.PAUSE) logging.debug(f"校准结束:当前位置[{cur_cp}]")
def click_drops(): click_zone = (win.left+200, win.top+200, 2, 2) print('exiting battle.') pyautogui.sleep(4) for i in range(6): click(click_zone, delay=0.2) return
def abre_programa(self, name, path=False): """ :param name: path/to/nameProgram :param path: False => contmatic, True => any path :return: winleft+r open """ if path is False: programa = contmatic_select_by_name(name) else: programa = name senha = '240588140217' sleep(1) pygui.hotkey('winleft', 'r') # pesquisador sleep(1) pygui.write(programa) sleep(1) pygui.hotkey('enter') sleep(10) # p.write(senha) # p.hotkey('tab', 'enter', interval=.5) pygui.sleep(5)
def do_clean_o2_filter(self): keep_going = True while keep_going: im = pyautogui.screenshot() nothing_left = False for i in range(730, 1390, 5): for j in range(120, 980, 5): pix = im.getpixel((i, j)) pix2 = (70, 77, 20) if self.is_approximate(pix, pix2, 9): if self.debug: print(i, j) pyautogui.moveTo(i, j) pyautogui.mouseDown() pyautogui.moveTo(620, 540) pyautogui.moveTo(300, 540) pyautogui.mouseUp() sleep(.1) im = pyautogui.screenshot() nothing_left = True if nothing_left == False: keep_going = False
def do_empty_garbage(self): print("daf") pyautogui.moveTo(1270, 430) pyautogui.mouseDown() pyautogui.moveTo(1270, 820, .2) sleep(3) pyautogui.mouseUp()
def press(key, dur, times): for i in range(0, times): print(key) pyautogui.keyDown(key) pyautogui.sleep(dur) pyautogui.keyUp(key) pyautogui.sleep(longkeypress)
def start_fresh_game(self): print("hitting esc to back out.") keyboard.send("esc") pag.sleep(1) print("finding the new game button") button = pag.locateOnScreen("new_game_main_screen_needle_image.png") if button: # fresh game, button is blue print(f"found blue button at {button}") pag.click(pag.center(button)) print("ready to start!") else: # continue game button is blue, new is white. print(f"found white button at {button}") button = pag.locateOnScreen("new_game_needle_image.png") pag.click(pag.center(button)) pag.sleep(1) button = pag.locateOnScreen( "new_game_main_screen_needle_image.png", confidence=.8) pag.click(pag.center(button)) print("ready to start!") # search for new_game button # if found then click it and wait # if not found then look for little arrow # click arrow - > click new game -> click confirm pass
def click(box, pad=(0, 0, 0, 0), delay=0.5): # clicks for the constant Locations and adds rx = random.randint(box[0] - pad[3], box[0] + box[2] + pad[1]) ry = random.randint(box[1] - pad[0], box[1] + box[3] + pad[2]) rx += win.left ry += win.top + top_pad pyautogui.click(rx, ry) pyautogui.sleep(delay)
def login(self, user = "******", password = "******"): pyautogui.write(user) pyautogui.press("tab") pyautogui.write(password) time.sleep(1) self.clickByLinkText("Anmelden") print("Eingeloggt als " + user + "...") pyautogui.sleep(1)
def move_mouse(x, y): pag.sleep(1) x = int(x / LOOP / FACTOR) y = int(y / LOOP / FACTOR) for i in range(10): ctypes.windll.user32.mouse_event(MOUSEEVENT_MOVE, x, y, 0, 0) pag.sleep(0.01)
def do_swipe_card(self): pyautogui.click(x=760, y=820) sleep(.3) pyautogui.moveTo(510, 490) pyautogui.mouseDown() pyautogui.moveTo(1430, 420, 3.2, pyautogui.easeInOutQuad) sleep(.1) pyautogui.mouseUp()
def upload_by_keys(file): """ base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) test_data_path = os.path.join(base_dir, 'test_data') filename = '{}{}{}'.format(test_data_path, os.sep, file) pyautogui.sleep(1) pyautogui.typewrite(filename, interval=0.5) pyautogui.press('enter', interval=0.5)
def func1(self): #pgui.moveTo(1336, 427, 3) #pgui.click() #pgui.typewrite(self.translate('проконтролировано'), interval=0.1) pgui.sleep(2) cb.copy("проконтролировано") #cb.paste() pgui.hotkey('ctrl', 'v')
def login(self, user, password, submit): pyautogui.write(user) pyautogui.press("tab") pyautogui.write(password) time.sleep(1) self.clickByClass(submit) # submit = submitButton Merkmal print_("Eingeloggt als " + user + "...") pyautogui.sleep(1)