How to use the uiautomation.SendKeys 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 / automation_help_demo.py View on Github external
def DemoEN():
    """for other language"""
    thisWindow = auto.GetConsoleWindow()
    auto.Logger.ColorfullyWrite('I will run cmd\n\n')
    time.sleep(3)

    auto.SendKeys('{Win}r')
    while not isinstance(auto.GetFocusedControl(), auto.EditControl):
        time.sleep(1)
    auto.SendKeys('cmd{Enter}')
    cmdWindow = auto.WindowControl(SubName = 'cmd.exe')
    rect = cmdWindow.BoundingRectangle
    auto.DragDrop(rect.left + 50, rect.top + 10, 50, 10)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('I will run Notepad and type Hello!!!\n\n')
    time.sleep(3)

    subprocess.Popen('notepad')
    notepadWindow = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad')
    cx, cy = auto.GetScreenSize()
    notepadWindow.MoveWindow(cx // 2, 20, cx // 2, cy // 2)
    time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
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)
        automation.Logger.Write('    @@to : ' if alert else '    to: ')
        automation.Logger.WriteLine(newName, automation.ConsoleColor.Yellow if alert else automation.ConsoleColor.Green)
    if depth + 1 > TreeDepth:
        return
    if automation.ExpandCollapseState.Collapsed == treeItem.CurrentExpandCollapseState():
        treeItem.Expand(0.1)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / wireshark_rtp_analyzer.py View on Github external
startIndex = info.find('Seq=')
                        if startIndex > 0:
                            endIndex = info.find(' ', startIndex)
                            packet.Seq = int(info[startIndex+4:endIndex].rstrip(','))
                        startIndex = info.find('Time=', startIndex)
                        if startIndex > 0:
                            endIndex = startIndex + 5 + 1
                            while str.isdigit(info[startIndex+5:endIndex]) and endIndex <= len(info):
                                packet.TimeStamp = int(info[startIndex+5:endIndex])
                                endIndex += 1
                            if packet.No >= beginNo:
                                packets.append(packet)
                                automation.Logger.WriteLine('No: {0[No]:<10}, Time: {0[Time]:<10}, Protocol: {0[Protocol]:<6}, Length: {0[Length]:<6}, Info: {0[Info]:<10},'.format(packet.__dict__))
            index = (index + 1) % len(headers)
            if item.BoundingRectangle[3] >= bottom:
                automation.SendKeys('{PageDown}')
                time.sleep(0.1)
    AnalyzePackets(packets, sampleRate, showLost)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / wireshark_rtp_analyzer.py View on Github external
def AnalyzeUI(sampleRate = 90000, payload = 96, beginNo = 0, maxPackets = 0xFFFFFFFF, showLost = False):
    """Wireshark version must >= 2.0"""
    wireSharkWindow = automation.WindowControl(searchDepth= 1, ClassName = 'Qt5QWindowIcon')
    if wireSharkWindow.Exists(0, 0):
        wireSharkWindow.SetActive()
    else:
        automation.Logger.WriteLine('can not find wireshark', automation.ConsoleColor.Yellow)
        return
    tree = wireSharkWindow.TreeControl(searchDepth= 4, SubName = 'Packet list')
    left, top, right, bottom = tree.BoundingRectangle
    tree.Click(10, 30)
    automation.SendKeys('{Home}{Ctrl}{Alt}4')
    time.sleep(0.5)
    tree.Click(10, 30)
    headers = []
    headerFunctionDict = {'No': int,
                          'Time': float,
                          'Source': str,
                          'Destination': str,
                          'Protocol': str,
                          'Length': int,
                          'Info': str,}
    index = 0
    payloadStr = 'PT=DynamicRTP-Type-' + str(payload)
    packets = []
    for item, depth in automation.WalkTree(tree
                                           , getFirstChildFunc= lambda c:c.GetFirstChildControl()
                                           , getNextSiblingFunc= lambda c:c.GetNextSiblingControl()):
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
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)
        automation.SendKeys('{Ctrl}s')
        while '*' in foxitWindow.Name:
            time.sleep(0.5)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
def BatchRename():
    foxitWindow = automation.WindowControl(searchDepth= 1, ClassName= 'classFoxitReader')
    foxitWindow.ShowWindow(automation.ShowWindow.ShowMaximized)
    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 = []
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
def BatchRename():
    foxitWindow = automation.WindowControl(searchDepth= 1, ClassName= 'classFoxitReader')
    foxitWindow.ShowWindow(automation.ShowWindow.ShowMaximized)
    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)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
tree.Click(y=50, waitTime=0.1)
    auto.SendKeys('{Home}', waitTime=0.1)
    columnCount = 0
    treeItemCount = 0
    for item, depth in auto.WalkControl(tree):
        if isinstance(item, auto.HeaderControl):
            columnCount += 1
            auto.Logger.Write(item.Name + ' ')
        elif isinstance(item, auto.TreeItemControl):
            if treeItemCount % columnCount == 0:
                auto.Logger.Write('\n')
                time.sleep(0.1)
            treeItemCount += 1
            auto.Logger.Write(item.Name + ' ')
            if item.BoundingRectangle.bottom >= rect.bottom:
                auto.SendKeys('{PageDown}', waitTime=0.1)
        if auto.IsKeyPressed(auto.Keys.VK_F1):
            auto.Logger.WriteLine('\nF1 pressed', auto.ConsoleColor.Yellow)
            break
github yinkaisheng / Python-UIAutomation-for-Windows / demos / notepadtop.py View on Github external
if len(sys.argv) == 2:
        isTop = int(sys.argv[1])

    note = automation.WindowControl(searchDepth=1, ClassName='Notepad')
    if note.Exists(0, 0):
        note.SetTopmost(isTop)
    else:
        subprocess.Popen('notepad')
        note.Refind()
        note.SetTopmost(isTop)
        note.Move(0, 0)
        note.Resize(400, 300)
        edit = automation.EditControl(searchFromControl=note)
        edit.Click()
        automation.SendKeys('I\'m a topmost window!!!')