pywinauto二次封装(pywinnat.py)
生活随笔
收集整理的這篇文章主要介紹了
pywinauto二次封装(pywinnat.py)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
將pywinauto常用方法進行封裝,使得pywinauto用起來更簡單
#頭文件的引入 from pywinauto import application from pywinauto import clipboard import SendKeys import win32api import win32con import os, sys, time#二次封裝的類 class Pywin(object): #======================= # pywin framwork main class #=======================SLEEP_TIME = 1#初始化方法,初始化一個appdef __init__(self):self.app = application.Application()#啟動應用程序def run(self, tool_name):self.app.start_(tool_name)time.sleep(self.SLEEP_TIME)#連接應用程序def connect(self, tool_name):self.app.connect_(tool_name)time.sleep(self.SLEEP_TIME)#關閉應用程序def close(self, tool_name):window_name = window_name.decode('utf-8')self.app[window_name].Close()#最大化窗口def max_window(self, window_name):window_name = window_name.decode('utf-8')self.app[window_name].Maximize()time.sleep(self.SLEEP_TIME)#菜單點擊def menu_click(self, window_name, menulist):window_name = window_name.decode('utf-8')menulist = menulist.decode('utf-8')self.app[window_name].MenuSelect(menulist)time.sleep(self.SLEEP_TIME)#輸入內容def input(self, window_name, controller, content):window_name = window_name.decode('utf-8')controller = controller.decode('utf-8')content = content.decode('utf-8')self.app[window_name][controller].TypeKeys(content)time.sleep(self.SLEEP_TIME)#鼠標左鍵點擊def click(self, window_name, controller, x = 0,y = 0):window_name = window_name.decode('utf-8')controller = controller.decode('utf-8')self.app[window_name][controller].Click(button = "left", pressed = "", coords = (x, y))time.sleep(self.SLEEP_TIME)#鼠標左鍵點擊(雙擊)def double_click(self, window_name, controller, x = 0,y = 0):window_name = window_name.decode('utf-8')controller = controller.decode('utf-8')self.app[window_name][controller].DoubleClick(button = "left", pressed = "", coords = (x, y))time.sleep(self.SLEEP_TIME)#鼠標右鍵點擊,菜單選擇def right_click(self, window_name, controller, order):window_name = window_name.decode('utf-8')controller = controller.decode('utf-8')self.app[window_name][controller].RightClick()for down in range(order):SendKeys.SendKeys('{DOWN}')time.sleep(0.5)SendKeys.SendKeys('{ENTER}')time.sleep(self.SLEEP_TIME)#獲取剪切板內容def getclipboard(self):return clipboard.GetData(format = 13)#使用win32點擊屏幕def win32_left_click(self, (x, y), times):for count in range(times):win32api.SetCursorPos((x, y))win32api.mouse_event(win32con.MOUSEEVqENTF_LEFTDOWN, 0, 0, 0,0)win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0,0)time.sleep(self.SLEEP_TIME)#使用win32點擊屏幕def win32_right_click(self, (x, y), times):for count in range(times):win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVqENTF_RIGHTDOWN, 0, 0, 0,0)win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0,0)time.sleep(self.SLEEP_TIME)if __name__ == '__main__':app = Pywin()#app.run('notepad.exe')
?
轉載于:https://www.cnblogs.com/ybcao/p/5459915.html
總結
以上是生活随笔為你收集整理的pywinauto二次封装(pywinnat.py)的全部內容,希望文章能夠幫你解決所遇到的問題。