예제 #1
0
 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}')
예제 #2
0
def install_qttabbar():
    print('Installing Qttabbar.....')
    wget.download(
        'http://qttabbar.wdfiles.com/local--files/qttabbar1/QTTabBar_1043.zip',
        rf"{path}\software\QTTabBar.zip")
    os.system(
        rf"{path}\tools\7za.exe x {path}\software\QTTabBar.zip -o{path}\software"
    )
    os.system(rf"{path}\software\QTTabBar.exe /qi")
    qttabbar = False
    for win in Desktop(backend="uia").windows():
        if win.class_name() == "CabinetWClass":
            break
    else:
        qttabbar = True
        Application(backend="uia").start('explorer.exe')
        win = Desktop(backend="uia").window(class_name="CabinetWClass")
    win.set_focus()
    keyboard.send_keys("{VK_MENU}")
    keyboard.send_keys("{V}")
    time.sleep(0.5)
    keyboard.send_keys("{Y}")
    keyboard.send_keys("{DOWN}")
    keyboard.send_keys("{DOWN}")
    keyboard.send_keys("{DOWN}")
    keyboard.send_keys("{ENTER}")
    if qttabbar:
        win.close()
    os.system('cls')
예제 #3
0
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
예제 #4
0
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
예제 #5
0
def is_window_pixel_white(title, x, y):
    dlg = Desktop(backend="win32").window(title_re=title)
    dlg.set_focus()
    left, top, right, bot = getrect(dlg.handle)
    im = pyautogui.screenshot(region=(left, top, right - left, bot - top))
    return im.getpixel((int(x), int(y))) == (255, 255, 255)
예제 #6
0
    def OnSend(self, event):
        try:
            self.m_send.Disable()
            if not hyhr_key.Hyhr_key.IsKeyValid(hyhr_key.KEY.Key):
                logger.error(hyhr_def.HYHR_KEY_ERROR)
                wx.MessageBox(hyhr_def.HYHR_KEY_ERROR)
                return
            else:
                logger.info(hyhr_def.HYHR_KEY_VALID)
            #check key exists
            # if not os.path.isfile(key):
            # 	wx.MessageBox('认证码不存在,请先到菜单文件--认证中输入认证码')
            # 	logger.error('认证码不存在')
            # 	return
            # else:
            # 	with open(key, 'r', encoding='utf-8') as k:
            # 		data = k.read()
            # 		key_date = datetime.datetime.strptime(hyhr_encrypt.Decrypt(data.encode()),hyhr_def.HYHR_KEY_FORMAT)
            # 		if hyhr_encrypt.Global_Cur_Date:
            # 			cur_date = datetime.datetime.strptime(hyhr_encrypt.Global_Cur_Date,hyhr_def.HYHR_KEY_FORMAT)
            # 		else:
            # 			cur_date = datetime.datetime.strptime(hyhr_encrypt.GetCurDate(),hyhr_def.HYHR_KEY_FORMAT)
            # 		if cur_date > key_date:
            # 			wx.MessageBox(hyhr_def.HYHR_KEY_EXPIRED)
            # 			logger.error(hyhr_def.HYHR_KEY_EXPIRED)
            # 			return
            # 		else:
            # 			logger.info('认证码有效!')
            self.msg = self.m_richText3.GetValue()
            if len(self.names) == 0 or (len(self.msg) == 0
                                        and len(self.file) == 0):
                wx.MessageBox(hyhr_def.HYHR_NAME_MSG_FILE_EMPTY)
                logger.error(hyhr_def.HYHR_NAME_MSG_FILE_EMPTY)
                return

            if not os.path.isfile(wechat):
                wx.MessageBox(hyhr_def.HYHR_WECHAT_NOT_INSTALLED)
                logger.error(hyhr_def.HYHR_WECHAT_NOT_INSTALLED)
                return
            app = Application(backend='uia').start(wechat)
            try:
                dlg = Desktop(backend='uia').window(
                    class_name=wechat_class_name)
                dlg.set_focus()
            except Exception as ex:
                wx.MessageBox(hyhr_def.HYHR_WECHAT_NOT_STARTED)
                logger.error(f'{hyhr_def.HYHR_WECHAT_NOT_STARTED} {ex}')
                return
            wrapper = dlg.wrapper_object()
            wrapper.click_input(coords=(searchbox_x, searchbox_y))

            counter = 0
            for info in self.names:
                name = None
                data = []
                vals = []
                validData = True
                info = info.strip()
                if not len(info):
                    continue
                vals = re.split(r'\s+', info)
                length = len(vals)
                if length >= 1:
                    name = vals[0]
                else:
                    logger.warning('异常数据,忽略.')
                    counter += 1
                    continue

                if len(self.msg):
                    for i in range(1, length):
                        try:
                            fee = float(vals[i])
                            data.append(fee)
                        except Exception as ex:
                            logger.warning('异常数值:{}!暂不发送,请核对后重试!'.format(info))
                            validData = False
                            break

                if not validData:
                    counter += 1
                    continue

                try:
                    wrapper.click_input(coords=(searchbox_x, searchbox_y))
                    wrapper.type_keys(name)
                    time.sleep(1.5)
                    wrapper.click_input(coords=(searchbox_x, searchResult_y))
                    noFoundDlg = Desktop(backend='uia').window(
                        class_name=wechat_notFound_class_name)
                    #time.sleep(0.5)
                    if noFoundDlg.exists(timeout=2):
                        noFoundDlg.close()
                        logger.warning('{} 不存在,请手工确认'.format(name))
                        time.sleep(1)
                        counter += 1
                        continue

                    if len(self.msg):
                        if len(data) == 0:
                            dlg.type_keys(self.msg.replace('{', '').replace(
                                '}', ''),
                                          with_spaces=True)
                        else:
                            if '{}' in self.msg:
                                if self.msg.count('{}') == len(data):
                                    dlg.type_keys(self.msg.format(*data),
                                                  with_spaces=True)
                                else:
                                    logger.warning(
                                        f'{name} 数据数目和消息格式不匹配,忽略该条记录!')
                                    counter += 1
                                    continue
                            else:
                                dlg.type_keys(self.msg, with_spaces=True)
                        dlg.type_keys('%{s}')
                        logger.info('发送消息给{}成功'.format(name))

                    if len(self.file):
                        #try to send file
                        #for f in os.listdir(self.file):
                        wrapper.click_input(coords=(sendfile_x, sendfile_y))
                        #pywinauto.keyboard.send_keys(self.file)
                        pywinauto.keyboard.send_keys(self.file)
                        pywinauto.keyboard.send_keys('{ENTER 1}')
                        dlg.type_keys('%{s}')
                        logger.info('发送文件{}给{}成功'.format(self.file, name))

                    self.m_namesList.SetItem(counter, 1, '✔')
                    self.m_namesList.SetItemTextColour(counter, wx.GREEN)
                    self.m_namesList.itemDataMap[counter] = (name, '✔')
                    counter += 1

                except Exception as ex:
                    #wx.MessageBox('发送错误!{}.'.format(ex))
                    logger.warning(f'{hyhr_def.HYHR_SEND_ERROR}{ex}.')
                    counter += 1
        except Exception as ex:
            wx.MessageBox(f'{hyhr_def.HYHR_SEND_ERROR}{ex}.')
            logger.error(f'{hyhr_def.HYHR_SEND_ERROR} {ex}.')
        finally:
            self.m_send.Enable()
        event.Skip()
예제 #7
0
파일: hycz_uia.py 프로젝트: woodhfut/hywx
namesFile = os.path.join(root_dir, '名单.txt')
failedNamesFile = os.path.join(root_dir, '发送失败人员名单.txt')
filesRootPath = os.path.join(root_dir, '文件')
bNeedSendFile = os.path.exists(filesRootPath) and len(
    os.listdir(filesRootPath))
bNeedSendMsg = os.path.isfile(msgFile) and os.stat(msgFile).st_size

assert os.path.isfile(namesFile), '名单不存在'
assert bNeedSendMsg or bNeedSendFile, '信息文件不存或者没有要发送的文件'

#app = Application(backend='uia').start(r'C:\Program Files\WindowsApps\TencentWeChatLimited.forWindows10_2.6.3.0_x86__sdtnhv12zgd7a\WeChatStore\WeChatStore.exe')
app = Application(
    backend='uia').start(r'C:\Program Files (x86)\Tencent\WeChat\WeChat.exe')
try:
    dlg = Desktop(backend='uia').window(class_name='WeChatMainWndForPC')
    dlg.set_focus()
except:
    print('未能发现桌面版微信,退出!')
    sys.exit()
wrapper = dlg.wrapper_object()

#try to locate the search textbox
width = 100
height = 30
retry = 5
while retry > 0:
    wrapper.click_input(coords=(width, height))
    if dlg['3'].exists(timeout=2):
        break
    else:
        retry -= 1
예제 #8
0
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()
예제 #9
0
def install_maya():
    timings.Timings.slow()
    gdown.download(
        "https://drive.google.com/uc?export=download&id=1aegNaJNkPhueiSWu_JSOkDGwdDWsQZls",
        output=rf"{path}\software\Maya2020.4.7z")
    os.system('cls')
    os.system(
        rf"{path}\tools\7za.exe x {path}\software\Maya2020.4.7z -o{path}\software"
    )
    os.system('cls')
    print('Installing Autodesk Maya 2020.....')
    os.system('".\\software\\Autodesk Maya 2020.4\\Setup.exe" --silent')
    Application(backend='uia').start(
        "C:\\Program Files\\Autodesk\\Maya2020\\bin\\maya.exe")
    time.sleep(10)
    maya = Desktop(backend='uia').window(title="IE WebBrowser")
    maya.set_focus()
    maya.Hyperlink2.click_input()
    maya = Desktop(backend='uia').window(title="Autodesk Licensing")
    maya.set_focus()
    maya['I Agree Enter'].click_input()
    maya['Activate Enter'].click_input()
    maya = Desktop(backend='uia').window(
        title="Autodesk Licensing - Activation Options")
    maya.set_focus()
    maya.Edit1.click_input()
    maya.type_keys("666")
    maya.Edit2.click_input()
    maya.type_keys("69696969")
    maya.Next.click_input()
    maya = Desktop(backend='uia').window(
        title="Autodesk Licensing - Activating")
    maya.set_focus()
    time.sleep(5)
    maya.Static12.click_input()
    maya['Yes Enter'].click_input()
    maya = Desktop(backend='uia').window(title="Autodesk Licensing")
    maya.set_focus()
    maya['Activate Enter'].click_input()
    maya = Desktop(backend='uia').window(
        title="Autodesk Licensing - Activation Options")
    maya.set_focus()
    maya.Edit1.click_input()
    maya.type_keys("666")
    maya.Edit2.click_input()
    maya.type_keys("69696969")
    maya.Next.click_input()
    input("Please provide request code manually: ")
    Application(backend="uia").start(cmd_line='.\\software\\xf-adesk20_v2.exe')
    xforce = Desktop(backend='uia').window(
        title="Autodesk 2020 live Keymaker - X-FORCE")
    xforce.set_focus()
    xforce['Request :Edit'].click_input(button="right")
    dsk.Context.SelectAll.click_input()
    keyboard.send_keys("{VK_DELETE}")
    keyboard.send_keys("^v")
    xforce.CButton.click_input()
    xforce.OKButton.click_input()
    xforce.GButton.click_input()
    xforce['Activation :Edit'].click_input(button="right")
    dsk.Context.SelectAll.click_input()
    keyboard.send_keys("^c")
    os.system("TASKKILL /F /IM xf-adesk20_v2.exe")
    maya.set_focus()
    maya['I have an activation code from Autodesk'].click_input()
    maya.Edit1.click_input()
    keyboard.send_keys("^v")
    maya.Next.click_input()
    maya = Desktop(backend='uia').window(
        title="Autodesk Licensing - Activation Complete")
    maya.FinishButton.click_input()
    time.sleep(3)
    os.system("TASKKILL /F /IM maya.exe")
    os.system('cls')