How to use the uiautomation.Keys 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 / collapse_tree_item_under_cursor.py View on Github external
break
        stopEvent.wait(0.05)
    auto.Logger.WriteLine('HotKeyFunc exit')


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--main', action='store_true', help='exec main')
    args = parser.parse_args()

    if args.main:
        main()
    else:
        auto.Logger.WriteLine('move mouse to a tree control and press Ctrl+3', auto.ConsoleColor.Green)
        auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_3): lambda event: HotKeyFunc(event, ['--main'])},
                                 (auto.ModifierKey.Control, auto.Keys.VK_4))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / get_qq_group_members.py View on Github external
qqWindow = listItem.GetTopWindow()
    list = listItem.GetParentControl()
    allListItems = list.GetChildren()
    for listItem in allListItems:
        automation.Logger.WriteLine(listItem.Name)
    answer = input('是否获取详细信息?按y和Enter继续\n')
    if answer.lower() == 'y':
        automation.Logger.WriteLine('\n3秒后开始获取QQ群成员详细资料,您可以一直按住F10键暂停脚本')
        time.sleep(3)
        qqWindow.SetActive()
		#确保群里第一个成员可见在最上面
        list.Click()
        list.SendKeys('{Home}', waitTime = 1)
        for listItem in allListItems:
            if listItem.ControlType == automation.ControlType.ListItemControl:
                if automation.Win32API.IsKeyPressed(automation.Keys.VK_F10):
                    if consoleWindow:
                        consoleWindow.SetActive()
                    input('\n您暂停了脚本,按Enter继续\n')
                    qqWindow.SetActive()
                listItem.RightClick()
                menu = automation.MenuControl(searchDepth= 1, ClassName = 'TXGuiFoundation')
                menuItems = menu.GetChildren()
                for menuItem in menuItems:
                    if menuItem.Name == '查看资料':
                        menuItem.Click()
                        break
                automation.Logger.WriteLine(listItem.Name, automation.ConsoleColor.Green)
                automation.Logger.WriteLine(GetPersonDetail())
                listItem.Click()
                automation.SendKeys('{Down}')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / hide_window_with_hotkey.py View on Github external
parser = argparse.ArgumentParser()
    parser.add_argument('--main', action='store_true', help='exec main')
    parser.add_argument('--hide', action='store_true', help='hide window')
    parser.add_argument('--show', action='store_true', help='show window')
    args = parser.parse_args()

    if args.main:
        if args.hide:
            hide()
        elif args.show:
            show()
    else:
        subprocess.Popen('notepad')
        auto.GetConsoleWindow().SetActive()
        auto.Logger.ColorfullyWriteLine('Press Ctr+1 to hide\nPress Ctr+2 to show\n')
        auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_1): lambda e: HotKeyFunc(e, ['--main', '--hide']),
                            (auto.ModifierKey.Control, auto.Keys.VK_2): lambda e: HotKeyFunc(e, ['--main', '--show']),
                          },
                           (auto.ModifierKey.Control, auto.Keys.VK_9))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
def DemoCN():
    """for Chinese language"""
    thisWindow = auto.GetConsoleWindow()
    auto.Logger.ColorfullyWrite('我将运行cmd并设置它的屏幕缓冲区使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(RegexName = '.+cmd.exe')
    cmdWindow.TitleBarControl().RightClick()
    auto.SendKey(auto.Keys.VK_P)
    optionWindow = cmdWindow.WindowControl(SubName = '属性')
    optionWindow.TabItemControl(SubName = '选项').Click()
    optionTab = optionWindow.PaneControl(SubName = '选项')
    checkBox = optionTab.CheckBoxControl(AutomationId = '103')
    if checkBox.GetTogglePattern().ToggleState != auto.ToggleState.On:
        checkBox.Click()
    checkBox = optionTab.CheckBoxControl(AutomationId = '104')
    if checkBox.GetTogglePattern().ToggleState != auto.ToggleState.On:
        checkBox.Click()
    optionWindow.TabItemControl(SubName = '布局').Click()
    layoutTab = optionWindow.PaneControl(SubName = '布局')
    layoutTab.EditControl(AutomationId='301').GetValuePattern().SetValue('300')
    layoutTab.EditControl(AutomationId='303').GetValuePattern().SetValue('3000')
    layoutTab.EditControl(AutomationId='305').GetValuePattern().SetValue('140')
    layoutTab.EditControl(AutomationId='307').GetValuePattern().SetValue('30')
    optionWindow.ButtonControl(AutomationId = '1').Click()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_firefox.py View on Github external
newTabButton = tab.ButtonControl(searchDepth= 1)
    newTabButton.Click()
    edit = firefoxWindow.EditControl()
    # edit.Click()
    edit.SendKeys('https://www.bing.com/?rb=0&setmkt=en-us&setlang=en-us{Enter}')
    time.sleep(2)
    searchEdit = firefoxWindow.Control(Compare = lambda c, d:
        (isinstance(c, automation.EditControl) or isinstance(c, automation.ComboBoxControl)) and c.Name == 'Enter your search term')
    searchEdit.Click()
    searchEdit.SendKeys('Python-UIAutomation-for-Windows site:github.com{Enter}', 0.05)
    link = firefoxWindow.HyperlinkControl(SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    try:
        automation.Win32API.PressKey(automation.Keys.VK_CONTROL)
        link.Click()  #press control to open the page in a new tab
    except Exception as ex:
        automation.Win32API.ReleaseKey(automation.Keys.VK_CONTROL)
        raise
    newTab = tab.TabItemControl(SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    newTab.Click()
    starButton = firefoxWindow.ButtonControl(Name = 'Star this repository')
    if starButton.Exists(5):
        automation.GetConsoleWindow().SetActive()
        automation.Logger.WriteLine('Star Python-UIAutomation-for-Windows after 2 seconds', automation.ConsoleColor.Yellow)
        time.sleep(2)
        firefoxWindow.SetActive()
        time.sleep(1)
        starButton.Click()
        time.sleep(2)
    else:
        unstarButton = firefoxWindow.ButtonControl(Name = 'Unstar this repository')
        if unstarButton.Exists(0, 0):
            automation.GetConsoleWindow().SetActive()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / expand_tree_item_under_cursor.py View on Github external
parser = argparse.ArgumentParser()
    parser.add_argument('--main', action='store_true', help='exec main')
    parser.add_argument('-d', '--depth', type=int, default=0xFFFFFFFF,
                        help='max expand tree depth')
    parser.add_argument('-r', '--root', action='store_true', help='expand from root')
    parser.add_argument('-p', '--print', action='store_true', help='print tree node text', dest="print_")
    args = parser.parse_args()

    if args.main:
        ExpandFromRoot = args.root
        MaxExpandDepth = args.depth
        PrintTree = args.print_
        main()
    else:
        auto.Logger.WriteLine('move mouse to a tree control and press Ctrl+1', auto.ConsoleColor.Green)
        auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_1): lambda event: HotKeyFunc(event, ['--main'] + sys.argv[1:])},
                                 (auto.ModifierKey.Control, auto.Keys.VK_2))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
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 / automation_firefox.py View on Github external
firefoxWindow.SetActive()
    time.sleep(1)
    tab = firefoxWindow.TabControl()
    newTabButton = tab.ButtonControl(searchDepth= 1)
    newTabButton.Click()
    edit = firefoxWindow.EditControl()
    # edit.Click()
    edit.SendKeys('https://www.bing.com/?rb=0&setmkt=en-us&setlang=en-us{Enter}')
    time.sleep(2)
    searchEdit = firefoxWindow.Control(Compare = lambda c, d:
        (isinstance(c, automation.EditControl) or isinstance(c, automation.ComboBoxControl)) and c.Name == 'Enter your search term')
    searchEdit.Click()
    searchEdit.SendKeys('Python-UIAutomation-for-Windows site:github.com{Enter}', 0.05)
    link = firefoxWindow.HyperlinkControl(SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    try:
        automation.Win32API.PressKey(automation.Keys.VK_CONTROL)
        link.Click()  #press control to open the page in a new tab
    except Exception as ex:
        automation.Win32API.ReleaseKey(automation.Keys.VK_CONTROL)
        raise
    newTab = tab.TabItemControl(SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    newTab.Click()
    starButton = firefoxWindow.ButtonControl(Name = 'Star this repository')
    if starButton.Exists(5):
        automation.GetConsoleWindow().SetActive()
        automation.Logger.WriteLine('Star Python-UIAutomation-for-Windows after 2 seconds', automation.ConsoleColor.Yellow)
        time.sleep(2)
        firefoxWindow.SetActive()
        time.sleep(1)
        starButton.Click()
        time.sleep(2)
    else:
github yinkaisheng / Python-UIAutomation-for-Windows / demos / expand_tree_item_under_cursor.py View on Github external
parser.add_argument('--main', action='store_true', help='exec main')
    parser.add_argument('-d', '--depth', type=int, default=0xFFFFFFFF,
                        help='max expand tree depth')
    parser.add_argument('-r', '--root', action='store_true', help='expand from root')
    parser.add_argument('-p', '--print', action='store_true', help='print tree node text', dest="print_")
    args = parser.parse_args()

    if args.main:
        ExpandFromRoot = args.root
        MaxExpandDepth = args.depth
        PrintTree = args.print_
        main()
    else:
        auto.Logger.WriteLine('move mouse to a tree control and press Ctrl+1', auto.ConsoleColor.Green)
        auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_1): lambda event: HotKeyFunc(event, ['--main'] + sys.argv[1:])},
                                 (auto.ModifierKey.Control, auto.Keys.VK_2))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / hide_window_with_hotkey.py View on Github external
parser.add_argument('--show', action='store_true', help='show window')
    args = parser.parse_args()

    if args.main:
        if args.hide:
            hide()
        elif args.show:
            show()
    else:
        subprocess.Popen('notepad')
        auto.GetConsoleWindow().SetActive()
        auto.Logger.ColorfullyWriteLine('Press Ctr+1 to hide\nPress Ctr+2 to show\n')
        auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_1): lambda e: HotKeyFunc(e, ['--main', '--hide']),
                            (auto.ModifierKey.Control, auto.Keys.VK_2): lambda e: HotKeyFunc(e, ['--main', '--show']),
                          },
                           (auto.ModifierKey.Control, auto.Keys.VK_9))