def press_enter(): #press enter instead of clicking on the element because click() blocks spec_dlg = Desktop(backend="uia")["Login"] spec_dlg.set_focus() #restore is a cheap hack to select the window spec_dlg.restore() keyboard.SendKeys('{ENTER}')
def focus_and_click(title, x, y, tries=3, double=False): while tries > 0: try: dlg = Desktop(backend="win32").window(title_re=title) dlg.restore() dlg.set_focus() time.sleep(0.1) dlg.click_input(coords=(int(x), int(y)), double=double) return True except Exception as e: print('[!] Trouble focusclicking') print(e) tries -= 1 return False
def focus_and_click_image(title, image, tries=3): while tries > 0: try: dlg = Desktop(backend="win32").window(title_re=title) dlg.restore() dlg.set_focus() time.sleep(0.1) x, y = pyautogui.locateCenterOnScreen(image) pyautogui.click(int(x), int(y)) return True except Exception as e: print('[!] Trouble imageclicking') print(e) tries -= 1 return False
# 设置标题信息的txt文件路径 title_txt_file = txt_path + "title.txt" # 设置检测记录信息的txt文件路径 record_txt_file = txt_path + "record.txt" # 设置中文编码格式 # if sys.getdefaultencoding() != 'gbk': # importlib.reload(sys) # sys.setdefaultencoding('gbk') # 打开计算器应用 app = Application(backend="uia").start("calc.exe") dlg_spec = Desktop(backend="uia").window(title=u"计算器", visible_only=False) dlg_spec.restore() # 打印控件信息到指定路径 dlg_spec.print_control_identifiers(filename=control_txt_name) """ # 读取控件信息txt文件 fr = open(control_txt_name, "r") # 设置正则表达式,用于提取button控件的title par = r'.+title=\"([^,]+)\".+\"Button\"' content = [] for line in fr.readlines(): res = re.compile(par).findall(line) if res: result = str(res[0]).split(',')
def focus_on_window(task): spec_dlg = Desktop(backend="uia")["%s" %task] spec_dlg.set_focus() #restore is a cheap hack to select the window spec_dlg.restore()