def test1(stopEvent):
    c = automation.GetRootControl()
    n = 0
    while True:
        if stopEvent.is_set():
            break
        print(n)
        n += 1
        stopEvent.wait(1)
    print('test1 exits')
Ejemplo n.º 2
0
def hide():
    root = automation.GetRootControl()
    for window in root.GetChildren():
        if window.ClassName in WindowsWantToHide:
            automation.Logger.WriteLine('hide window, handle {}'.format(
                window.Handle))
            window.Hide()
            fin = open('hide_windows.txt', 'wt')
            fin.write(str(window.Handle) + '\n')
            fin.close()
Ejemplo n.º 3
0
def WalkDesktop():
    def GetFirstChild(control):
        return control.GetFirstChildControl()

    def GetNextSibling(control):
        return control.GetNextSiblingControl()

    desktop = automation.GetRootControl()
    for control, depth in automation.WalkTree(desktop, getFirstChildFunc=GetFirstChild, getNextSiblingFunc=GetNextSibling, includeTop=True, maxDepth= 1):
        print(' ' * depth * 4 + str(control))
def main(args):
    if args.time > 0:
        time.sleep(args.time)
    start = time.clock()
    if args.active:
        c = automation.GetForegroundControl()
    elif args.cursor or args.up:
        c = automation.ControlFromCursor()
    elif args.fullscreen:
        c = automation.GetRootControl()
    CaptureControl(c, args.path, args.up)
    automation.Logger.WriteLine('cost time: {:.3f} s'.format(time.clock() -
                                                             start))
def main():
    th = threading.currentThread()
    auto.Logger.WriteLine(
        'This is running in main thread. {} {}'.format(th.ident, th.name),
        auto.ConsoleColor.Cyan)
    time.sleep(2)
    auto.GetConsoleWindow().CaptureToImage('console_mainthread.png')
    root = auto.GetRootControl()
    auto.EnumAndLogControl(root, 1)
    th = threading.Thread(target=threadFunc, args=(root, ))
    th.start()
    th.join()
    auto.Logger.WriteLine(
        '\nMain thread exits. {} {}'.format(th.ident, th.name),
        auto.ConsoleColor.Cyan)
def CaptureControl(c, path, up=False):
    if c.CaptureToImage(path):
        automation.Logger.WriteLine('capture image: ' + path)
        subprocess.Popen(path, shell=True)
    else:
        automation.Logger.WriteLine('capture failed',
                                    automation.ConsoleColor.Yellow)
    if up:
        r = automation.GetRootControl()
        depth = 0
        name, ext = os.path.splitext(path)
        while True:
            c = c.GetParentControl()
            if not c or automation.ControlsAreSame(c, r):
                break
            depth += 1
            savePath = name + '_p' * depth + ext
            if c.CaptureToImage(savePath):
                automation.Logger.WriteLine('capture image: ' + savePath)
def threadFunc(uselessRoot):
    """
    If you want to use UI Controls in a new thread, create an UIAutomationInitializerInThread object first.
    But you can't use use a Control or a Pattern created in a different thread.
    So you can't create a Control or a Pattern in main thread and then pass it to a new thread and use it.
    """
    # print(uselessRoot)# you cannot use uselessRoot because it is a control created in a different thread
    _uiobj = auto.UIAutomationInitializerInThread(debug=True)
    th = threading.currentThread()
    auto.Logger.WriteLine(
        '\nThis is running in a new thread. {} {}'.format(th.ident, th.name),
        auto.ConsoleColor.Cyan)
    time.sleep(2)
    auto.GetConsoleWindow().CaptureToImage('console_newthread.png')
    newRoot = auto.GetRootControl(
    )  # ok, root control created in current thread
    auto.EnumAndLogControl(newRoot, 1)
    auto.Logger.WriteLine('\nThread exits. {} {}'.format(th.ident, th.name),
                          auto.ConsoleColor.Cyan)