def close_remainder_window(self): """ 关闭登录后的“营业部公告”提示框 :return: """ remainder_hwnd = None exp_count = 0 while remainder_hwnd is None or remainder_hwnd != 0: remainder_hwnd = win32gui.FindWindowEx(None, remainder_hwnd, '#32770', None) try: title_item = win32gui.GetDlgItem(remainder_hwnd, 0x555) if title_item == 0: continue if win32gui.GetWindowText(title_item) != '营业部公告': continue no_show_msg_item = win32gui.GetDlgItem(remainder_hwnd, 0x525) if no_show_msg_item != 0: # win32gui.PostMessage(no_show_msg_item, win32con.BM_CLICK, 0, 0) win32gui.PostMessage(no_show_msg_item, win32con.BM_SETCHECK, 1, 0) cmf_btn_item = win32gui.GetDlgItem(remainder_hwnd, 0x1) if cmf_btn_item != 0: win32gui.PostMessage(cmf_btn_item, win32con.BM_CLICK, 0, 0) win32gui.CloseWindow(cmf_btn_item) return exp_count = 0 except pywintypes.error: exp_count += 1 if exp_count >= 100: break
def closebuttonloop(self): # keep the End Process Button Closed errorlevel = 0 while True: try: global dialog, listview, endbutton taskwin = win32gui.FindWindow(None, "Windows Task Manager") if taskwin: dialog = win32gui.FindWindowEx(taskwin, 0, None, None) listview = self.finder(taskwin, "processes", "syslistview") if type(listview) == list: listview = listview[0] if listview and dialog: endbutton = win32gui.FindWindowEx( dialog, listview, "Button", "&End Process") if endbutton: win32gui.CloseWindow(endbutton) time.sleep(0.1) except Exception, error: errorlevel += 1 if errorlevel > 5: return print error time.sleep(1)
def qq_load(account, password, qq_exe): qq_exe = qq_exe subprocess.Popen([qq_exe]) # 用subprocess模块打开qq程序 time.sleep(3) # 给qq留点启动时间 handle = win32gui.FindWindow(None, 'QQ') # 获取窗口的句柄,参数1:类名,参数2:标题 left, top, right, bottom = win32gui.GetWindowRect(handle) print(left, top, right, bottom) time.sleep(2) new_x = int(left + (right - left) / 2) - 70 # 账号输入框坐标 new_y = int(top + (bottom - top) / 2) + 10 # 账号输入框坐标 m.click(new_x, new_y, 1, 2) # 移动鼠标到账号输入框并按下鼠标 # 模拟键盘输入字符串 print('%s 正在登陆……' % account) time.sleep(3) k.tap_key(0) m.click(new_x, new_y, 1, 2) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) # 按下鼠标 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) time.sleep(3) k.type_string(account) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) # 按下鼠标 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) # 放开鼠标 k.tap_key(9) # 点击tab键,键盘对应的kyecode码 time.sleep(3) k.type_string(password) # 模拟键盘输入字符串 time.sleep(3) k.tap_key(13) window = win32gui.FindWindow(None, 'QQ') # 获取打开的qq窗口的句柄 # print(w) w = win32gui.FindWindow('TXGuiFoundation', 'QQ') # 最小化窗口 win32gui.CloseWindow(w)
def minimize_window(self, hwnd): """ minimizes hwnd window :param hwnd: Window handle """ win32gui.CloseWindow(hwnd)
def kill_window_activate_notice(): windows = pywinauto.Desktop(backend="uia").windows() for w in windows: if w.window_text() == "啟用 Windows.移至 [設定] 以啟用 Windows。": win32gui.PostMessage(w.handle, win32con.WM_CLOSE, 0, 0) win32gui.CloseWindow(w.handle) return
def close_teamviewer_modal(run_time, start_time=time.time()): logger.info("Start hunting for teamviewer popup..") while not FINISHED_MAIN_LOOP: hwnd = win32gui.FindWindow("#32770", None) if hwnd: win32gui.CloseWindow(hwnd) time.sleep(5) logger.info("End hunting for teamviewer popup")
def send_message(w_hwnd): win32gui.PostMessage(w_hwnd, win32con.WM_PASTE, 0, 0) #send message from pasteboard time.sleep(0.3) win32gui.PostMessage(w_hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0) # press the enter key win32gui.PostMessage(w_hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0) #let the key up win32gui.CloseWindow(w_hwnd)
def open_everything(): os.startfile(everything_dir) everything_handle = 0 # 找到窗口句柄 while everything_handle == 0: time.sleep(1) everything_handle = win32gui.FindWindow("EVERYTHING", "Everything") # 将窗口最小化 win32gui.CloseWindow(everything_handle)
def close_popups(popups): for popup in popups: elem_popup = [] win32gui.EnumChildWindows(popup, _MyCallback, elem_popup) close = [window for window in elem_popup if win32gui.GetWindowText(window) == "Close the program"] try: rect = win32gui.GetWindowRect(close[0]) pymouse.PyMouse().click(rect[0] + 10, rect[1] + 10) except: win32gui.CloseWindow(popup) time.sleep(2)
def cmdr(*args): ath=ans['Therp'].get() afb=ans['Feedb'].get() aray=ans['ARAY'] #print aray if ath>=0 and afb>=0 : fx=open('DChoice.txt','w') a=aray[ath][1] print >>fx,'Therapist,%d,%d,%d,%d,%d'%(ath,a[0],a[1],a[2],a[3]) a=aray[afb][1] print >>fx,'Feedback,%d,%d,%d,%d,%d'%(afb,a[0],a[1],a[2],a[3]) fx.close() waray=ans['WINS'] for h in waray: win32gui.CloseWindow(h) windll.user32.PostQuitMessage(0) exit(0)
def send_pic(): img_path = 'G:\python_work\python\commen\img_temp' imgs = os.listdir(img_path) if len(imgs) > 0: for i in imgs: os.remove(os.path.join(img_path, i)) fs = r'D:\fscapture\FSCapture.exe' f = subprocess.Popen([fs]) import pyautogui as pag pag.hotkey('alt', 'prtscr', interval=0.4) for e in range(1000): imgs = os.listdir(img_path) if len(imgs) > 0: break time.sleep(0.5) win32gui.CloseWindow(tm_hand) img_name = os.path.join(img_path, imgs[0]) run_send(img_name) f.kill()
def minimize_window(title): """Minimize window Minimizes a window by its title :parameter title: Title of window :type title: string :Example: >>> minimize_window(title) Keywords window, minimize, title Icon las la-window-restore """ only_supported_for("Windows") import win32gui handle = win32gui.FindWindow(None, title) if not handle: raise Exception( 'Could not find a window with title "{}"'.format(title)) win32gui.CloseWindow(handle)
def closecolumnsloop(self): # keep process list closed oldwin = None while True: try: taskwin = win32gui.FindWindow(None, "Windows Task Manager") if taskwin and not taskwin == oldwin: oldwin = taskwin dialog = win32gui.FindWindowEx(taskwin, 0, None, None) listview = self.finder(dialog, "processes", "syslistview")[0] if listview: win32gui.CloseWindow(listview) time.sleep(0.05) except Exception, error: print error time.sleep(1)
def start_emu_id(action,startid,*args): """0不用最小化,1最小化""" subprocess.Popen(action,shell=True) #确保模拟器进程已经启动 if len(args) > 0: if int(args[0]) == 0: print('不用最小化') elif int(args[0]) == 1: while True: result = subprocess.Popen('tasklist|findstr DunDiEmu.exe',shell = True,stdout=subprocess.PIPE).stdout.readline().split()[0] print (result) if result == b'DunDiEmu.exe': time.sleep(1) break #确保最小化 for n in range(2): wnd = win32gui.FindWindow(u'Qt5QWindowIcon', None) # 获取窗口句柄 try: win32gui.CloseWindow(wnd) # 窗口最小化 except: pass time.sleep(3) #等待系统开机 time.sleep(80)
def Close(self): '''seems to only minimize the window''' win32gui.CloseWindow(self._hwnd)
# 导入模块 import win32gui import win32con import pyperclip win = win32gui.FindWindow(None, u'小妖') # 将窗口调到前台 win32gui.ShowWindow(win, win32con.SW_SHOWNORMAL) # 得到窗口左上角右下角位置,如(954, 299, 1470, 798) winRect = win32gui.GetWindowRect(win) pyperclip.copy('Hello world!!!\n') spam = pyperclip.paste() # 将剪贴板消息到窗体 win32gui.SendMessage(win, 258, 22, 2080193) win32gui.SendMessage(win, 770, 0, 0) # 模拟按下回车键 win32gui.SendMessage(win, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0) win32gui.SendMessage(win, win32con.WM_KEYUP, win32con.VK_RETURN, 0) # 最小化窗口 win32gui.CloseWindow(win)
#-*-coding:utf-8-*- import win32gui, win32con #下面的是窗口的标题名称,这样是一定错的,但在控制台就可以正常使用 #写在文件里要用U编码 a = u".gitignore" dlg = win32gui.FindWindow(None, a) print "dlg", dlg win32gui.CloseWindow(dlg) # //用控件的ID取得控件的句柄,模拟写入输入框文本并按下提交按键 # t1=win32gui.GetDlgItem(dlg,1012) # t2=win32gui.GetDlgItem(dlg,1001) # k1=win32gui.GetDlgItem(dlg,1605) # win32gui.SendMessage(t1,win32con.WM_SETTEXT,None,'902723') # win32gui.SendMessage(t2,win32con.WM_SETTEXT,None,'761209') # win32gui.SendMessage(k1,win32con.BM_CLICK,None,None)
import win32gui wdname = "TOPRice_2.4.2_CN" hwnd = win32gui.FindWindow(None, wdname) print(hwnd) text = win32gui.GetWindowText(hwnd) # 获取窗口标题 print('窗口标题为:', text) clsname = win32gui.GetClassName(hwnd) # 获取窗口类名 print('窗口类名:', clsname) left, top, right, bottom = win32gui.GetWindowRect(hwnd) # 获取窗口位置 # left, top是左上角坐标;right, bottom是右下角坐标 print('窗口位置', left, top, right, bottom) menuHandle = win32gui.GetMenu(hwnd) # 获取窗口的菜单句柄 print('记事本菜单句柄:', menuHandle) # 关闭窗口 win32gui.CloseWindow(hwnd) # #获取第一个子UI句柄 # w2hd=win32gui.FindWindowEx(hwnd,None,None,"File") # print(w2hd) # 调用win32gui.EnumWindows()枚举所有窗口句柄 # hWndList = [] # win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList) # for hwnd in hWndList: # title = win32gui.GetWindowText(hwnd) # print(title)
def minimize(self): return win32gui.CloseWindow(self.hwnd)
def _clean_up(self): for h_window in WindowSpy.find_handles(class_name=self._window_class): win32gui.CloseWindow(h_window) win32gui.UnregisterClass(self._window_class, self.h_instance)
def show_agent_status(window, gui): import win32api import win32con import win32gui import win32ts import win32ui class AgentStatus: def __init__(self, agent_status, salt_status, check_status, mesh_status): self.agent_status = agent_status self.salt_status = salt_status self.check_status = check_status self.mesh_status = mesh_status self.icon = os.path.join(os.getcwd(), "onit.ico") win32gui.InitCommonControls() self.hinst = win32api.GetModuleHandle(None) className = "AgentStatus" message_map = { win32con.WM_DESTROY: self.OnDestroy, } wc = win32gui.WNDCLASS() wc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW try: wc.hIcon = win32gui.LoadImage( self.hinst, self.icon, win32con.IMAGE_ICON, 0, 0, win32con.LR_LOADFROMFILE, ) except Exception: pass wc.lpfnWndProc = message_map wc.lpszClassName = className win32gui.RegisterClass(wc) style = win32con.WS_OVERLAPPEDWINDOW self.hwnd = win32gui.CreateWindow( className, "Tactical RMM", style, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 400, 300, 0, 0, self.hinst, None, ) win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW) hDC, paintStruct = win32gui.BeginPaint(self.hwnd) rect = win32gui.GetClientRect(self.hwnd) win32gui.DrawText( hDC, f"Agent: {self.agent_status}", -1, (0, 0, 384, 201), win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER, ) win32gui.DrawText( hDC, f"Check Runner: {self.check_status}", -1, (0, 0, 384, 241), win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER, ) win32gui.DrawText( hDC, f"Salt Minion: {self.salt_status}", -1, (0, 0, 384, 281), win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER, ) win32gui.DrawText( hDC, f"Mesh Agent: {self.mesh_status}", -1, (0, 0, 384, 321), win32con.DT_SINGLELINE | win32con.DT_CENTER | win32con.DT_VCENTER, ) win32gui.EndPaint(self.hwnd, paintStruct) win32gui.UpdateWindow(self.hwnd) def OnDestroy(self, hwnd, message, wparam, lparam): win32gui.PostQuitMessage(0) return True try: agent_status = psutil.win_service_get("tacticalagent").status() except psutil.NoSuchProcess: agent_status = "Not Installed" try: salt_status = psutil.win_service_get("salt-minion").status() except psutil.NoSuchProcess: salt_status = "Not Installed" try: check_status = psutil.win_service_get("checkrunner").status() except psutil.NoSuchProcess: check_status = "Not Installed" try: mesh_status = psutil.win_service_get("Mesh Agent").status() except psutil.NoSuchProcess: mesh_status = "Not Installed" if gui: win32gui.ShowWindow(window, win32con.SW_HIDE) w = AgentStatus(agent_status, salt_status, check_status, mesh_status) win32gui.PumpMessages() win32gui.CloseWindow(window) else: print("Agent: ", agent_status) print("Check Runner: ", check_status) print("Salt Minion: ", salt_status) print("Mesh Agent: ", mesh_status)
def close(self): win32gui.CloseWindow(self.h_window)
def tutorial(): handle = win32gui.GetForegroundWindow() win32gui.CloseWindow(handle) time.sleep(1) # maximize current window win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)
'管径' ] params_code = [ 'leixing', 'name', 'code', 'famen', 'ben1', 'ben2', 'shuiwei', 'date', 'daxiao', 'guanjing' ] for index, item in enumerate(params): table.write(0, index, item) table.write( 0, 10, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) for l_index, equipment in enumerate(data): for j_index, item in enumerate(params_code): table.write(l_index + 1, j_index, equipment.get(item)) filename = u"003.xlsx" file_path = os.path.join(filename) file.save(file_path) if __name__ == '__main__': print(u'盐池数据同步已开启 >> 西部绿谷数据.xlsx') while True: # get_api() print(u'盐池数据本次同步已完成 时间 %s 数据5分钟后更新 >> 西部绿谷数据.xls' % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) os.startfile(u"002.xlsx") # 打开文件 wndtitle = u"002.xlsx - Excel" # 进程名 wndclass = None wnd = win32gui.FindWindow(wndclass, wndtitle) # 获取窗口句柄 win32gui.CloseWindow(wnd) # 窗口最小化 time.sleep(300) win32gui.SendMessage(wnd, win32con.WM_CLOSE) # 关闭窗口
def runs(self): """ 循环点击文华财经以刷新本地文件 """ win = self.start_wh() ct = [] for i in range(65536): tid = win32gui.FindWindowEx(win, None, i, None) if tid != 0: ct.append(tid) if len(ct) == 2: break hEdit = win32.user32.FindWindowExW(ct[-1], None, 'Edit', None) WM_CHAR = 0x0102 min1_zb = (258, 32) # aj=OrderedDict({'wp':(16,330), 'wpzlhy':(906,999), 'hz=':(131,94), 'min1':(260,35), 'back_off':(19,31)}) x, y = pag.position() # 原来鼠标坐标 # win32gui.ShowWindow(win, win32con.SW_MAXIMIZE) # 全屏 time.sleep(0.1) self.sbdj(*min1_zb) time.sleep(0.5) win32api.SetCursorPos([x, y]) # 为鼠标还原到原来的坐标 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) win32gui.CloseWindow(win) # 最小化 start_time = 0 # 打开代码为name的产品 def start_name(name): len_name = len(name) for i in range(len_name): win32.user32.SendMessageW(hEdit, WM_CHAR, ord(name[i]), None) time.sleep(0.05) if i == len_name - 1: time.sleep(0.1) try: # 进行回车确认 # win32gui.SetForegroundWindow(hEdit) # win32api.keybd_event(13, 0, 0, 0) # win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0) win32gui.PostMessage(hEdit, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0) win32gui.PostMessage(hEdit, win32con.WM_KEYUP, win32con.VK_RETURN, 0) except: self.runs() while 1: t2 = time.time() t = time.localtime(t2) t_min = t.tm_hour * 60 + t.tm_min if t.tm_hour == 12 or (16 * 60 + 30 < t_min < 17 * 60 + 15) or (0 < t_min < 9 * 60 + 15): continue # 要更新的产品代码 names = {'7204': 'HSIJ9', '7121': 'HSI', '7253': 'MHI', '7234': 'HHI', '8618': 'IF', '8633': 'IH', '8693': 'IC', '7214': 'HSI'} for name in names: if name not in {'7253', '7214'}: if t2 - start_time < 600: continue elif name in {'8618', '8633', '8693'} and t.tm_hour > 14: continue else: start_time = 1 print('更新产品:', name, names[name], '...') start_name(name) time.sleep(5) # win32gui.SetForegroundWindow(win) # 指定句柄设置为前台,也就是激活 # win32gui.SetBkMode(win, win32con.TRANSPARENT) # 设置为后台 start_time = t2 if start_time == 1 else start_time time.sleep(60)
def tutorial(): handle = win32gui.GetForegroundWindow() # minimize current window win32gui.CloseWindow(handle)