def get_tft_window() -> Union[Win32Window, None]: windows = auto.getAllWindows() window = [ window for window in windows if window.title == Wrappers.ACTIVE_WINDOW ] if window: window = window[0] if Wrappers.ACTIVE_WINDOW != Wrappers.LAUNCHER: return window else: children = [] def foreach_child(hwnd: int, lparam: int): children.append(auto.Window(hwnd & 0xFFFFFFFF)) return True win32gui.EnumChildWindows(window._hWnd, enumChildWindowsProc(foreach_child), 0) children_by_name = [ window for window in children if window.title == Wrappers.LAUNCHER_CONTROL ] if children_by_name: return children_by_name[0] else: return None
def is_focused(window_title): winlist = pyautogui.getAllWindows() for win in winlist: if window_title in win.title: if win.isActive: return True else: return False
def focus_on_app(window_title): winlist = pyautogui.getAllWindows() for item in winlist: if window_title in item.title: if not item.maximize(): item.maximize() if not item.isActive: item.activate()
def get_vlc_window(): try: return [ window for window in pyautogui.getAllWindows() if 'VLC' in window.title ][0] except: pass
def focus_on_app(window_title, maximize=True, activate=True): winlist = pyautogui.getAllWindows() for item in winlist: if window_title in item.title: if maximize: if (not item.maximize()): item.maximize() if activate: if (not item.isActive): item.activate()
def setDFWindow(): global dfWindow for window in pyautogui.getAllWindows(): if (window.title == "" and window.height == dfWindowHeight and window.width == dfWindowWidth): dfWindow = window return # set window to None in case it was set previously dfWindow = None print("DragonFable window not found")
def close_window(win_name): ''' inputs : win_name , type : str output : None This function closes the given app_name window ''' print('Closing window ', win_name) winlist = pyautogui.getAllWindows() for window in winlist: if window.title == win_name: window.close() print("window closed ")
def get_screen_dimension(select_screen=True): wins_named = dict(zip(pyautogui.getAllTitles(), pyautogui.getAllWindows())) x = wins_named[windows_name].left y = wins_named[windows_name].top w = wins_named[windows_name].width h = wins_named[windows_name].height if select_screen: pyautogui.mouseDown(x + w / 2, y + h / 2) time.sleep(0.2) pyautogui.mouseUp() #return (x + 8, y + 52, x+w - 8, y+h - 10) return {"left": x + 8, "top": y + 52, "width": w - 16, "height": h - 62}
def print_all_windows(): winlist = pyautogui.getAllWindows() for win in winlist: print(win.title)
def minimize_window(window_title): winlist = pyautogui.getAllWindows() for item in winlist: if window_title in item.title: if (not item.minimize()): item.minimize()
def window_exist(window_title): winlist = pyautogui.getAllWindows() for win in winlist: if window_title in win.title: return True return False
def cexcel_from_html_above_v1(self, cliente, html_codigo): # # DEPOIS JUNTAR ELA COM GINFESS_SCRAP import os import pyautogui as pygui from pyperclip import paste, copy from time import sleep from .retornot import RetidosNorRetidos, RnrSo1 from .ginfess_scrap import cria_site_v1 """ :param cliente: nome do cliente vindo do loop :param competencia: vindo do GINFESS_download na linha 37 :param site_cria: (lugar_salvar) :return: return_full_path for with_titlePATH.txt """ client_path = self.client_path # impossível ser None driver = self.driver qtd_nf = driver.find_element_by_class_name('x-paging-info') qtd_text = qtd_nf.text proc = qtd_text.index('of') pal = qtd_text[proc:].split() qtd_text = pal[1] prossigo = cria_site_v1(html_codigo, qtd_text) _prossigo = prossigo[0] len_tables = prossigo[1] # input(f'{prossigo}, {len_tables}, {_prossigo}') sleep(5) if _prossigo: arq = f'rnc-{cliente}.xlsx' if len(arq) > 32: arq = f'rnc-{cliente.split()[0]}.xlsx' x, y = pygui.position() arq = f'{client_path}/{arq}' if '/' in client_path else f'{client_path}\\{arq}' # not really necessary, but i want to try: wb = Workbook() sh_name = client_path.split('/')[-1] if '\\' not in client_path else client_path.split('\\')[-1] sh_name = sh_name[:10] # limitando wb.create_sheet(sh_name) wb.active = 1 wb.remove(wb['Sheet']) wb.save(arq) except FileExistsError: pass finally: # ########## ABRINDO EXCEL ####### # program = arq.split('_')[-1] """~~~~""" os.startfile(arq) """~~~~""" sleep(12) allin = pygui.getAllWindows() for e, l in enumerate(allin): if program in l.title.lower(): l.restore() l.activate() l.maximize() # ########## ABRINDO ######### sleep(6) if len_tables > 1: RetidosNorRetidos() # input('RETIDOS N RETIDOS') pygui.hotkey('alt', 'f4') sleep(5) pygui.hotkey('enter') # from RETIDOS_N_RETIDOS import save_after_changes else: RnrSo1() print(f'Testado, len tables = {len_tables}')
"Experiment timer": None, "Lab Recorder": None } windowParameters = { "BrainVision LSL Viewer":{"topLeft":[320,0],"width":1624,"height":700}, "Figure 1: LSL:Stream'Shimmer_ppg'":{"topLeft":[-34,0],"width":396,"height":546}, "Figure 2: LSL:Stream'Shimmer_gsr'":{"topLeft":[-34,532],"width":396,"height":513}, "Figure 3: LSL:Stream'NB-2015.10.15'":{"topLeft":[320,0],"width":1624,"height":700}, "Figure 3: LSL:Stream'NB-2015.10.16'":{"topLeft":[320,0],"width":1624,"height":700}, "Experiment timer": {"topLeft":[1507,670],"width":420,"height":375}, "Lab Recorder": {"topLeft":[838, 670],"width":684,"height":375} } if __name__ == "__main__": windows = auto.getAllWindows() for w1 in windows: # print(w.title) if w1.title in windowDict.keys(): windowDict[w1.title] = w1 for name,w1 in windowDict.items(): if w1 is not None: print(name) print("top left", w1.topleft) print("width", w1.width) print("height", w1.height) #Move to default positions
import mov_det_screen_v1 as detector import HP_detection as HP import time import pyautogui import random pyautogui.FAILSAFE = True Action = False action_time = 0 win_index = pyautogui.getAllTitles().index('Old School RuneScape') #x0 = 1920-pyautogui.getAllWindows()[win_index].size.width + 20 x0 = pyautogui.getAllWindows()[win_index].topleft.x + 30 def eating_function(ptg, threshold, clicked_positions): inventory_positions = [[(1732, 769), (1774, 769), (1816, 769), (1858, 769)], [(1732, 805), (1774, 805), (1816, 805), (1858, 805)], [(1732, 841), (1774, 841), (1816, 841), (1858, 841)], [(1732, 877), (1774, 877), (1816, 877), (1858, 877)], [(1732, 913), (1774, 913), (1816, 913), (1858, 913)], [(1732, 949), (1774, 949), (1816, 949), (1858, 949)],
import pyautogui fw = pyautogui.getActiveWindow() # 현재 활성화된 창 (VSCode) print(fw.title) # 창의 제목 정보 print(fw.size) # 창의 크기 정보 (width, height) print(fw.left, fw.top, fw.right, fw.bottom) # 창의 좌표 정보 pyautogui.click(fw.left + 25, fw.top + 20) for w in pyautogui.getAllWindows(): print(w) # 모든 윈도우 가져오기
def adjust_desktop(): """ 调整桌面各窗口位置及大小 办公室,27寸,4k屏幕,125%缩放 """ for win in pyautogui.getAllWindows(): print( f'title={win.title}, left={win.left}, top={win.top}, width={win.width}, height={win.height}' ) screen_width = 3840 task_bar_height = 50 screen_height = 2160 - task_bar_height middle_width = screen_width / 2 middle_height = screen_height / 2 # 全屏 if '- Mozilla Thunderbird' in win.title: win.maximize() # # 左上 # elif 'Firefox Developer Edition' in win.title: # win.left = 80 # win.top = 0 # win.width = middle_width - win.left # win.height = middle_height # 居中 elif 'Firefox Developer Edition' in win.title or \ 'Mozilla Firefox' in win.title: win.left = (screen_width - middle_width) / 2 win.top = (screen_height - middle_height) / 2 win.width = middle_width win.height = middle_height # 左下 elif ' PyCharm' in win.title or '- PyCharm' in win.title: win.left = 0 win.top = middle_height win.width = middle_width win.height = middle_height # 右上 elif '- Oracle VM VirtualBox' in win.title: win.left = middle_width win.top = 0 win.width = middle_width win.height = middle_height # 右下 elif '- Visual Studio Code' in win.title or \ '- KiTTY' in win.title or \ '[foobar2000' in win.title: win.left = middle_width win.top = middle_height win.width = middle_width win.height = middle_height # 没连接终端时调整,调整后要重启 # elif 'MobaXterm' in win.title: # win.maximize() # 音量合成器 elif 'Volume Mixer -' in win.title: win.left = 2582 win.top = 1548 win.width = 1258 win.height = 462 # 左下,文件浏览器 elif '此电脑' in win.title or 'This PC' in win.title: win.left = 80 win.top = middle_height win.width = middle_width - 200 win.height = middle_height - 120 # 左下,远程连接 elif '- Remote Desktop Connection' in win.title or \ 'SumatraPDF' in win.title: win.left = 0 win.top = middle_height - 66 # im elif 'WeChat Work' in win.title or \ '企业微信' in win.title or \ '微信' in win.title or \ 'TIM' in win.title: win.left = 700 win.top = 1100 # win.width = 690 # win.height = 718 # edge elif '- Microsoft Edge' in win.title: win.left = middle_width win.top = 1900 win.width = middle_width win.height = 200
vbanEnable = Point(x=30, y=53) vbanWin = None def addp(p1, p2): return pyautogui.Point(x=p1.x + p2.x, y=p1.y + p2.y) def subp(p1, p2): return pyautogui.Point(x=p1.x - p2.x, y=p1.y - p2.y) try: voicemeeterWin = pyautogui.getAllWindows()[pyautogui.getAllTitles().index(voicemeeterWinTitle)] voicemeeterWin.activate() except ValueError: pyautogui.alert("Open VoiceMeeter Banana window before running this program.\nInstall it if it's not installed yet") exit(1) def vbanSetIn(addr, port): logger.info("setting vban in to %s:%d", addr, port) pyautogui.click(addp(vbanWin.topleft, vbanWinHeader)) time.sleep(minGuiDelay) pyautogui.click(addp(vbanWin.topleft, vbanInAddr1)) time.sleep(minGuiDelay) pyautogui.write(f"{addr}\n") time.sleep(minGuiDelay) pyautogui.click(addp(vbanWin.topleft, vbanInPort1))
def adjust_desktop(): """ 调整桌面各窗口位置及大小 家,32寸,4k屏幕,150%缩放 """ for win in pyautogui.getAllWindows(): print(win) screen_width = 3840 task_bar_height = 50 screen_height = 2160 - task_bar_height middle_width = screen_width / 2 middle_height = screen_height / 2 if '- Firefox Developer Edition' in win.title: win.left = 80 win.top = 0 win.width = middle_width - win.left - 20 win.height = middle_height elif '- Chromium' in win.title: win.left = middle_width win.top = 0 win.width = middle_width win.height = middle_height # 文件浏览器,this pc页面 elif 'This PC' in win.title: win.left = 80 win.top = middle_height win.width = middle_width - 200 win.height = middle_height - 120 elif 'Netease Music' in win.title: win.left = middle_width win.top = middle_height win.width = middle_width win.height = middle_height elif '- PyCharm' in win.title: win.left = 0 win.top = middle_height - 300 win.width = middle_width win.height = middle_height + 300 elif '- Visual Studio Code' in win.title: win.left = middle_width win.top = middle_height win.width = middle_width win.height = middle_height # 没连接终端时调整,调整后要重启 elif 'MobaXterm' in win.title: win.left = middle_width win.top = middle_height win.width = middle_width win.height = middle_height elif 'Volume Mixer -' in win.title: win.left = 2582 win.top = 1648 win.width = 1258 win.height = 462 elif '- Remote Desktop Connection' in win.title: win.left = 0 win.top = middle_height - 66 elif '[foobar2000' in win.title: win.left = middle_width win.top = middle_height win.width = middle_width win.height = middle_height