How to use the uiautomation.ControlFromPoint function in uiautomation

To help you get started, we’ve selected a few uiautomation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
# 采用特殊处理获取重命名菜单
            x, y = automation.Win32API.GetCursorPos()
            menuItem = automation.ControlFromPoint(x + 2, y + 2)
            if isinstance(menuItem, automation.MenuItemControl):
                #鼠标右下方弹出菜单
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y += 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            else:
                #鼠标右上方弹出菜单
                menuItem = automation.ControlFromPoint(x + 2, y - 2)
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y -= 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            if find:
                break
            else:
                automation.SendKeys('{Esc}')
                time.sleep(0.5)
        if not find:
            automation.Logger.Log('this pdf not support editing')
            exit(0)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y += 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            else:
                #鼠标右上方弹出菜单
                menuItem = automation.ControlFromPoint(x + 2, y - 2)
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y -= 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            if find:
                break
            else:
                automation.SendKeys('{Esc}')
                time.sleep(0.5)
        if not find:
            automation.Logger.Log('this pdf not support editing')
            exit(0)
        menuItem.Click(simulateMove = False, waitTime = 0.2)
        edit = automation.EditControl(searchFromControl= tree, searchDepth= 1)
        edit.SetValue(newName, waitTime = 0.05)
        automation.SendKeys('{Enter}', waitTime = 0.05)
        automation.Logger.Write('rename: ')
        automation.Logger.WriteLine(name, automation.ConsoleColor.Green)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
time.sleep(0.1)
        find = False
        for i in range(3):
            treeItem.RightClick(simulateMove = False, waitTime = 0.2)
            # FoxitReader书签右键菜单(BCGPToolBar,非Windows菜单)弹出后,枚举不到菜单,但从屏幕点上ControlFromPoint能获取到菜单, todo
            # 采用特殊处理获取重命名菜单
            x, y = automation.Win32API.GetCursorPos()
            menuItem = automation.ControlFromPoint(x + 2, y + 2)
            if isinstance(menuItem, automation.MenuItemControl):
                #鼠标右下方弹出菜单
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y += 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            else:
                #鼠标右上方弹出菜单
                menuItem = automation.ControlFromPoint(x + 2, y - 2)
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y -= 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            if find:
                break
            else:
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
for aid in ['59583', '60682', '60683']:
        editToolBar = automation.ToolBarControl(searchFromControl= foxitWindow, AutomationId = aid, Name = 'Caption Bar')
        if editToolBar.Exists(0, 0):
            editToolBar.Click(-40, 0.5)
            automation.SendKeys('{Alt}y')
    paneWindow = automation.WindowControl(searchFromControl= foxitWindow, AutomationId = '65280')
    bookmarkPane = automation.PaneControl(searchFromControl= paneWindow, searchDepth= 1, foundIndex= 1)
    l, t, r, b = bookmarkPane.BoundingRectangle
    #bookmarkButton = automation.ButtonControl(searchFromControl= bookmarkPane, Name = '书签') # can't find, but automation -a can find it, why
    if bookmarkPane.Name == '书签':
        if r - l < 40:
            bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
            if bookmarkButton.Name == '书签':
                bookmarkButton.Click(simulateMove= False)
    else:
        bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
        if bookmarkButton.Name == '书签':
            bookmarkButton.Click(simulateMove= False)
    tree = automation.TreeControl(searchFromControl= foxitWindow, ClassName= 'SysTreeView32')
    childItems = tree.GetChildren()
    bookMarks = []
    depth = 1
    for treeItem in childItems:
        if treeItem.ControlType == automation.ControlType.TreeItemControl:
            RenameTreeItem(tree, treeItem, bookMarks, depth)
    fout = open('rename_pdf_bookmark.txt', 'wt', encoding= 'utf-8')
    depth = 1
    for bookMark in bookMarks:
        DumpBookMark(fout, bookMark, depth)
    fout.close()
    if Renamed:
        automation.Logger.Log('rename pdf: ' + foxitWindow.Name)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
newName, alert = RenameFunction(name, removeChapter)
    if newName.startswith('Appendix'):
        removeChapter = False
    bookMark = BookMark(name, newName)
    bookMarks.append(bookMark)
    if newName != name and depth not in TreeSkipDepthList:
        global Renamed
        Renamed = True
        time.sleep(0.1)
        find = False
        for i in range(3):
            treeItem.RightClick(simulateMove = False, waitTime = 0.2)
            # FoxitReader书签右键菜单(BCGPToolBar,非Windows菜单)弹出后,枚举不到菜单,但从屏幕点上ControlFromPoint能获取到菜单, todo
            # 采用特殊处理获取重命名菜单
            x, y = automation.Win32API.GetCursorPos()
            menuItem = automation.ControlFromPoint(x + 2, y + 2)
            if isinstance(menuItem, automation.MenuItemControl):
                #鼠标右下方弹出菜单
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
                        break
                    y += 20
                    menuItem = automation.ControlFromPoint(x + 2, y)
                    if not isinstance(menuItem, automation.MenuItemControl):
                        break
            else:
                #鼠标右上方弹出菜单
                menuItem = automation.ControlFromPoint(x + 2, y - 2)
                while 1:
                    if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
                        find = True
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
ret = foxitWindow.SetActive()
    print('SetActive', ret)
    automation.Logger.Log(foxitWindow.Name[:-len(' - Foxit Reader')] + '\n')
    automation.SendKeys('{Ctrl}0')
    for aid in ['59583', '60682', '60683']:
        editToolBar = automation.ToolBarControl(searchFromControl= foxitWindow, AutomationId = aid, Name = 'Caption Bar')
        if editToolBar.Exists(0, 0):
            editToolBar.Click(-40, 0.5)
            automation.SendKeys('{Alt}y')
    paneWindow = automation.WindowControl(searchFromControl= foxitWindow, AutomationId = '65280')
    bookmarkPane = automation.PaneControl(searchFromControl= paneWindow, searchDepth= 1, foundIndex= 1)
    l, t, r, b = bookmarkPane.BoundingRectangle
    #bookmarkButton = automation.ButtonControl(searchFromControl= bookmarkPane, Name = '书签') # can't find, but automation -a can find it, why
    if bookmarkPane.Name == '书签':
        if r - l < 40:
            bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
            if bookmarkButton.Name == '书签':
                bookmarkButton.Click(simulateMove= False)
    else:
        bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
        if bookmarkButton.Name == '书签':
            bookmarkButton.Click(simulateMove= False)
    tree = automation.TreeControl(searchFromControl= foxitWindow, ClassName= 'SysTreeView32')
    childItems = tree.GetChildren()
    bookMarks = []
    depth = 1
    for treeItem in childItems:
        if treeItem.ControlType == automation.ControlType.TreeItemControl:
            RenameTreeItem(tree, treeItem, bookMarks, depth)
    fout = open('rename_pdf_bookmark.txt', 'wt', encoding= 'utf-8')
    depth = 1
    for bookMark in bookMarks: