Ejemplo n.º 1
0
def typeInNotepad(strText):
    Notepad.wndNotepad().Click()
    Win32API.SendKeys(strText)
Ejemplo n.º 2
0
def main():
    # if not IsPy3 and sys.getdefaultencoding() == 'ascii':
    # reload(sys)
    # sys.setdefaultencoding('utf-8')
    import getopt
    Logger.Write('UIAutomation {} (Python {}.{}.{}, {} bit)\n'.format(
        VERSION, sys.version_info.major, sys.version_info.minor,
        sys.version_info.micro, 64 if sys.maxsize > 0xFFFFFFFF else 32))
    options, args = getopt.getopt(sys.argv[1:], 'hrfcamnd:t:', [
        'help', 'root', 'focus', 'cursor', 'ancestor', 'showMore',
        'showAllName', 'depth=', 'time='
    ])
    root = False
    focus = False
    cursor = False
    ancestor = False
    showAllName = False
    showMore = False
    depth = 0xFFFFFFFF
    seconds = 3
    for (o, v) in options:
        if o in ('-h', '-help'):
            usage()
            exit(0)
        elif o in ('-r', '-root'):
            root = True
        elif o in ('-f', '-focus'):
            focus = True
        elif o in ('-c', '-cursor'):
            cursor = True
        elif o in ('-a', '-ancestor'):
            ancestor = True
        elif o in ('-n', '-showAllName'):
            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()
            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')
Ejemplo n.º 3
0
def openProgramViaRunDialog(program):
    Win32API.SendKeys("{LWIN}{R}")
    WaitForExist(Notepad.dlgRun(), 5)
    Win32API.SendKeys(program)
    Win32API.SendKeys("{ENTER}")