#!python3
# -*- coding: utf-8 -*-

import os
import sys
import time
import subprocess

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))  # not required after 'pip install uiautomation'
import uiautomation as automation


def main():
    subprocess.Popen('mmc.exe devmgmt.msc')
    time.sleep(1)
    mmcWindow = automation.WindowControl(searchDepth = 1, ClassName = 'MMCMainFrame')
    tree = mmcWindow.TreeControl()
    for item, depth in automation.WalkControl(tree, includeTop = True):
        if isinstance(item, automation.TreeItemControl):  #or item.ControlType == automation.ControlType.TreeItemControl
            item.Select()
            if automation.ExpandCollapseState.Collapsed == item.CurrentExpandCollapseState():
                item.Expand(0)
            automation.Logger.WriteLine(' ' * (depth - 1) * 4 + item.Name, automation.ConsoleColor.Green)
            time.sleep(0.1)

if __name__ == '__main__':
    main()
    automation.GetConsoleWindow().SetActive()
    input('\npress Enter to exit\n')

@@ -250,24 +250,70 @@
 def main():%0A
+    cmdWindow = automation.GetConsoleWindow()%0A
     subproce
@@ -961,16 +961,2249 @@
 ep(0.1)%0A
+    if cmdWindow:%0A        automation.Logger.ColorfulWriteLine('Scroll to top by SendKeys %3CColor=Cyan%3ECtrl+Home%3C/Color%3E')%0A        cmdWindow.SetActive(waitTime = 1)%0A    mmcWindow.SetActive(waitTime = 1)%0A    tree.SendKeys('%7BCtrl%7D%7BHome%7D', waitTime = 1)%0A    if cmdWindow:%0A        automation.Logger.ColorfulWriteLine('Scroll to bottom by SendKeys %3CColor=Cyan%3ECtrl+End%3C/Color%3E')%0A        cmdWindow.SetActive(waitTime = 1)%0A    mmcWindow.SetActive(waitTime = 1)%0A    tree.SendKeys('%7BCtrl%7D%7BEnd%7D', waitTime = 1)%0A    if cmdWindow:%0A        automation.Logger.ColorfulWriteLine('Scroll to top by %3CColor=Cyan%3EWheelUp%3C/Color%3E')%0A        cmdWindow.SetActive(waitTime = 1)%0A    #vScrollBar = tree.ScrollBarControl(AutomationId = 'NonClientVerticalScrollBar')# failed to get scollbar sometimes, why?%0A    vScrollBar = mmcWindow.ScrollBarControl(AutomationId = 'NonClientVerticalScrollBar')%0A    vScrollBarRect = vScrollBar.BoundingRectangle%0A    thumb = vScrollBar.ThumbControl()%0A    while True:%0A        vPercent = tree.CurrentVerticalScrollPercent()%0A        vPercent2 = vScrollBar.RangeValuePatternCurrentValue()%0A        print('TreeControl.CurrentVerticalScrollPercent', vPercent)%0A        print('ScrollBarControl.RangeValuePatternCurrentValue', vPercent)%0A        if vPercent2 %3E 0:%0A            tree.WheelUp(waitTime = 0.1)%0A        else:%0A            break%0A    if cmdWindow:%0A        automation.Logger.ColorfulWriteLine('Scroll to bottom by %3CColor=Cyan%3EWheelDown%3C/Color%3E')%0A        cmdWindow.SetActive(waitTime = 1)%0A    while True:%0A        vPercent = tree.CurrentVerticalScrollPercent()%0A        vPercent2 = vScrollBar.RangeValuePatternCurrentValue()%0A        print('TreeControl.CurrentVerticalScrollPercent', vPercent)%0A        print('ScrollBarControl.RangeValuePatternCurrentValue', vPercent)%0A        if vPercent2 %3C 100:%0A            tree.WheelDown(waitTime = 0.1)%0A        else:%0A            break%0A    if cmdWindow:%0A        automation.Logger.ColorfulWriteLine('Scroll by %3CColor=Cyan%3EDragDrop%3C/Color%3E')%0A        cmdWindow.SetActive(waitTime = 1)%0A    mmcWindow.SetActive(waitTime = 1)%0A    x, y = thumb.MoveCursorToMyCenter()%0A    automation.DragDrop(x, y, x, vScrollBarRect%5B1%5D)%0A    x, y = thumb.MoveCursorToMyCenter()%0A    automation.DragDrop(x, y, x, vScrollBarRect%5B3%5D)%0A%0A
 %0Aif __na
@@ -3232,24 +3232,36 @@
   main()%0A   
+ cmdWindow =
  automation.
@@ -3278,16 +3278,52 @@
 Window()
+%0A    if cmdWindow:%0A        cmdWindow
 .SetActi

modify demo