zoukankan      html  css  js  c++  java
  • 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
            #初始化方法,初始化一个app
            def __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')
  • 相关阅读:
    解决NopCommerce 在iis缓存目录Temporary ASP.NET Files下存在两个版本的dll问题(一)
    给select标签设置下拉框高度
    ASP.NET MVC里ModelState.IsValid总是true或者总是false
    ubuntu虚拟机安装Gitlab后出现“Whoops, GitLab is taking too much time to respond.”
    C# JavaScriptSerializer序列化时的时间处理
    强大的pdf文件操作小工具——PDFtk的小白用法
    MySQL--pt-osc工具学习
    如何正确地在Spring Data JPA和Jackson中用上Java 8的时间相关API(即JSR 310也即java.time包下的众神器)
    ExtJS 6.2.0 增加中文排序支持
    SpringBoot项目中SecureRandom导致的Controller访问非常慢的问题
  • 原文地址:https://www.cnblogs.com/ybcao/p/5459915.html
Copyright © 2011-2022 走看看