How to use the uiautomation.GetFocusedControl 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)
github yinkaisheng / Python-UIAutomation-for-Windows / scripts / automation.py View on Github external
control = auto.ControlFromCursor()
        if depth < 0:
            while depth < 0 and control:
                control = control.GetParentControl()
                depth += 1
            depth = 0xFFFFFFFF
    if ancestor:
        control = auto.ControlFromCursor()
        if control:
            auto.EnumAndLogControlAncestors(control, showAllName)
        else:
            auto.Logger.Write('IUIAutomation returns null element under cursor\n', auto.ConsoleColor.Yellow)
    else:
        indent = 0
        if not control:
            control = auto.GetFocusedControl()
            controlList = []
            while control:
                controlList.insert(0, control)
                control = control.GetParentControl()
            if len(controlList) == 1:
                control = controlList[0]
            else:
                control = controlList[1]
                if foreground:
                    indent = 1
                    auto.LogControl(controlList[0], 0, showAllName)
        auto.EnumAndLogControl(control, depth, showAllName, startDepth=indent)
    auto.Logger.Log('Ends\n')
github yinkaisheng / Python-UIAutomation-for-Windows / automation.py View on Github external
showAllName = True
        elif o in ('-m', '-showMore'):
            showMore = True
        elif o in ('-d', '-depth'):
            depth = int(v)
        elif o in ('-t', '-time'):
            seconds = int(v)
    if seconds > 0:
        Logger.Write('please wait for {0} seconds\n\n'.format(seconds), writeToFile=False)
        time.sleep(seconds)
    Logger.Log('Starts, Current Cursor Position: {}'.format(Win32API.GetCursorPos()))
    control = None
    if root:
        control = GetRootControl()
    if focus:
        control = GetFocusedControl()
    if cursor:
        control = ControlFromCursor()
        if depth < 0:
            while depth < 0:
                control = control.GetParentControl()
                depth += 1
            depth = 0xFFFFFFFF
    if ancestor:
        control = ControlFromCursor()
        if control:
            EnumAndLogControlAncestors(control, showAllName, showMore)
        else:
            Logger.Write('IUIAutomation return null element under cursor\n', ConsoleColor.Yellow)
    else:
        if not control:
            control = GetFocusedControl()
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 = '布局')
github yinkaisheng / Python-UIAutomation-for-Windows / scripts / automation.py View on Github external
foreground = False
        elif o in ('-n', '-showAllName'):
            showAllName = True
        elif o in ('-d', '-depth'):
            depth = int(v)
        elif o in ('-t', '-time'):
            seconds = int(v)
    if seconds > 0:
        auto.Logger.Write('please wait for {0} seconds\n\n'.format(seconds), writeToFile=False)
        time.sleep(seconds)
    auto.Logger.Log('Starts, Current Cursor Position: {}'.format(auto.GetCursorPos()))
    control = None
    if root:
        control = auto.GetRootControl()
    if focus:
        control = auto.GetFocusedControl()
    if cursor:
        control = auto.ControlFromCursor()
        if depth < 0:
            while depth < 0 and control:
                control = control.GetParentControl()
                depth += 1
            depth = 0xFFFFFFFF
    if ancestor:
        control = auto.ControlFromCursor()
        if control:
            auto.EnumAndLogControlAncestors(control, showAllName)
        else:
            auto.Logger.Write('IUIAutomation returns null element under cursor\n', auto.ConsoleColor.Yellow)
    else:
        indent = 0
        if not control:
github yinkaisheng / Python-UIAutomation-for-Windows / automation.py View on Github external
if cursor:
        control = ControlFromCursor()
        if depth < 0:
            while depth < 0:
                control = control.GetParentControl()
                depth += 1
            depth = 0xFFFFFFFF
    if ancestor:
        control = ControlFromCursor()
        if control:
            EnumAndLogControlAncestors(control, showAllName, showMore)
        else:
            Logger.Write('IUIAutomation return null element under cursor\n', ConsoleColor.Yellow)
    else:
        if not control:
            control = GetFocusedControl()
            controlList = []
            while control:
                controlList.insert(0, control)
                control = control.GetParentControl()
            if len(controlList) == 1:
                control = controlList[0]
            else:
                control = controlList[1]
        EnumAndLogControl(control, depth, showAllName, showMore)
    Logger.Log('Ends\n')