def main():
    if auto.IsNT6orHigher:
        oriTitle = auto.GetConsoleOriginalTitle()
    else:
        oriTitle = auto.GetConsoleTitle()
    auto.SetConsoleTitle(auto.GetConsoleTitle() + ' | Ctrl+1,Ctrl+2, stop Ctrl+4')
    auto.Logger.ColorfullyWriteLine('Press <Color=Cyan>Ctrl+1 or Ctrl+2</Color> to start, press <Color=Cyan>ctrl+4</Color> to stop')
    auto.Logger.Write('\nUse UIAutomation in main thread:\n', auto.ConsoleColor.Yellow)
    auto.LogControl(auto.GetRootControl())
    auto.Logger.Write('\n')
    auto.RunByHotKey({(auto.ModifierKey.Control, auto.Keys.VK_1): test1,
                              (auto.ModifierKey.Control, auto.Keys.VK_2): test2},
                             (auto.ModifierKey.Control, auto.Keys.VK_4))
    auto.SetConsoleTitle(oriTitle)
Exemple #2
0
#!python3
# -*- coding: utf-8 -*-
# hide windows with hotkey Ctrl+1, show the hidden windows with hotkey Ctrl+2
import os
import sys
import time
import subprocess
from threading import Event

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


def capture(stopEvent: Event):
    with auto.UIAutomationInitializerInThread(debug=True):
        control = auto.ControlFromCursor()
        control.CaptureToImage('control.png')
        subprocess.Popen('control.png', shell=True)


if __name__ == '__main__':
    auto.SetConsoleTitle('Capture: Ctrl+1, Exit: Ctrl+D')
    auto.Logger.ColorfullyWriteLine(
        'Press <Color=Green>Ctr+1</Color> to capture a control image under mouse corsor'
    )
    auto.RunByHotKey({
        (auto.ModifierKey.Control, auto.Keys.VK_1): capture,
    })
    # Show doesn't call any COM methods, so it doesn't need an UIAutomationInitializerInThread
    for handle in handles:
        win = auto.ControlFromHandle(handle)
        win.Show(0)
        if auto.IsIconic(handle):
            win.ShowWindow(auto.SW.Restore, 0)


if __name__ == '__main__':
    for i in range(2):
        subprocess.Popen('notepad.exe')
        time.sleep(1)
        notepad = auto.WindowControl(searchDepth=1, ClassName='Notepad')
        notepad.MoveWindow(i * 400, 0, 400, 300)
        notepad.SendKeys('notepad {}'.format(i + 1))
    auto.SetConsoleTitle('Hide: Ctrl+1, Show: Ctrl+2, Exit: Ctrl+D')
    cmdWindow = auto.GetConsoleWindow()
    if cmdWindow:
        cmdWindow.GetTransformPattern().Move(0, 300)
    auto.Logger.ColorfullyWriteLine(
        'Press <Color=Green>Ctr+1</Color> to hide the windows\nPress <Color=Green>Ctr+2</Color> to show the windows\n'
    )
    handles = [
        win.NativeWindowHandle for win in auto.GetRootControl().GetChildren()
        if win.ClassName in WindowsWantToHide
    ]
    auto.RunByHotKey(
        {
            (auto.ModifierKey.Control, auto.Keys.VK_1):
            lambda event: hide(event, handles),
            (auto.ModifierKey.Control, auto.Keys.VK_2):
Exemple #4
0
                                    auto.ConsoleColor.Yellow)
    tree = wiresharkWindow.TreeControl(searchDepth=4,
                                       ClassName='PacketList',
                                       Name='Packet list')
    rect = tree.BoundingRectangle
    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_F12):
            auto.Logger.WriteLine('\nF12 pressed', auto.ConsoleColor.Yellow)
            break


if __name__ == '__main__':
    auto.SetConsoleTitle(auto.GetConsoleTitle() + ' | press F12 to stop')
    walk()
    time.sleep(2)