Esempio n. 1
0
 def login(self):
     subprocess.Popen("D:\Tencent\QQ\Bin\QQ.exe")  #启动QQ
     username = uiautomation.WindowControl(Name="QQ")
     username.ComboBoxControl(Name="QQ号码").Click()
     username.ComboBoxControl(Name="QQ号码").SendKeys("1109355448")
     uiautomation.SendKey(uiautomation.Keys.VK_ENTER)  # 按回车键
     self.qun()
     self.quns()
Esempio n. 2
0
# -*- coding: utf-8 -*-

import uiautomation as automation
import time

frame = automation.WindowControl(searchDepth=1, ClassName = 'ApplicationFrameWindow')
frame.SetFocus()
time.sleep(2)
automation.SendKey(automation.Keys.VK_F12)
time.sleep(2)
frame.Minimize()
time.sleep(2)
frame.Maximize()
window1 = frame.WindowControl(searchDepth=1, ClassName = 'Windows.UI.Core.CoreWindow')
# window_custom = window1.WindowControl(searchDepth=1, AutomationId = 'm_f12Docked')
window_customs = window1.GetChildren()
for window_custom in window_customs:
	# print(window_custom)
	pass

window_custom = window1.CustomControl(searchDepth=1, AutomationId = 'm_f12Docked')
# print(window_custom)
children = window_custom.GetChildren()
g = window_custom.GroupControl(searchDepth=1)
f12 = g.PaneControl(searchDepth=1)
f12 = f12.PaneControl(searchDepth=1)
f12 = f12.PaneControl(searchDepth=1, AutomationId='9')
f12 = f12.PaneControl(searchDepth=1, Name='Network')
toolbar = f12.ToolBarControl(searchDepth=1)
button = toolbar.ButtonControl(searchDepth=1, Name='清除会话')
contentFilter = toolbar.ButtonControl(searchDepth=1, Name = '内容类型筛选器')
def DemoCN():
    """for Chinese language"""
    thisWindow = auto.GetConsoleWindow()
    auto.Logger.ColorfullyWrite(
        '我将运行<Color=Cyan>cmd</Color>并设置它的<Color=Cyan>屏幕缓冲区</Color>使<Color=Cyan>cmd</Color>一行能容纳很多字符\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='布局')
    layoutTab.EditControl(AutomationId='301').GetValuePattern().SetValue('300')
    layoutTab.EditControl(
        AutomationId='303').GetValuePattern().SetValue('3000')
    layoutTab.EditControl(AutomationId='305').GetValuePattern().SetValue('140')
    layoutTab.EditControl(AutomationId='307').GetValuePattern().SetValue('30')
    optionWindow.ButtonControl(AutomationId='1').Click()
    cmdWindow.SetActive()
    rect = cmdWindow.BoundingRectangle
    auto.DragDrop(rect.left + 50, rect.top + 10, 50, 30)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite(
        '我将运行<Color=Cyan>记事本</Color>并输入<Color=Cyan>Hello!!!</Color>\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)
    time.sleep(1)

    dir = os.path.dirname(__file__)
    scriptPath = os.path.abspath(os.path.join(dir, '..\\automation.py'))

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite(
        '运行"<Color=Cyan>automation.py -h</Color>"显示帮助\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -h'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite(
        '运行"<Color=Cyan>automation.py -r -d1</Color>"显示所有顶层窗口, 即桌面的子窗口\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -r -d1 -t0'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite(
        '运行"<Color=Cyan>automation.py -c</Color>"显示鼠标光标下的控件\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -c -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)
    cmdWindow.SetActive(waitTime=2)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite(
        '运行"<Color=Cyan>automation.py -a</Color>"显示鼠标光标下的控件和它的所有父控件\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -a -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)
    cmdWindow.SetActive(waitTime=2)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite(
        '运行"<Color=Cyan>automation.py</Color>"显示当前激活窗口和它的所有子控件\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.EditControl().Click()
    time.sleep(3)
    cmdWindow.SetActive(waitTime=2)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.WriteLine('演示结束,按Enter退出', auto.ConsoleColor.Green)
    input()
Esempio n. 4
0
# 定位菜单栏中的“文件”
menu = note_window.MenuItemControl(Name="文件(F)")
menu.Click()

# 在“文件”菜单的子菜单中找到“保存”,点击
# save = uiautomation.MenuItemControl(Name="保存(S)")
# save.Click()

# 点击“文件”后,按三次“下”,在按一次“回车”,保存文件
# uiautomation.SendKey(uiautomation.Keys.VK_DOWN)
# uiautomation.SendKey(uiautomation.Keys.VK_DOWN)
# uiautomation.SendKey(uiautomation.Keys.VK_DOWN)
# uiautomation.SendKey(uiautomation.Keys.VK_ENTER)

# 利用快捷键保存文件内容,键入S
uiautomation.SendKey(uiautomation.Keys.VK_S)

# 由于在之前的操作完成后,光标自动进入文件名输入域
# 故,直接在新弹出的文件管理窗口,输入保存的文件路径和文件名
uiautomation.SendKeys(r"C:\Users\aragale\Desktop\demo.txt")

# 点击文件管理窗口的“保存”按钮
uiautomation.ButtonControl(Name="保存(S)").Click()

time.sleep(1)

# 检查文件是否存在
is_file = os.path.exists(r"C:\Users\aragale\Desktop\demo.txt")
# 或者
# is_file = os.path.isfile(r"C:\Users\aragale\Desktop\demo.txt")
if is_file:
Esempio n. 5
0
    def prepare(self):
        time.sleep(3)
        automation.SendKey(automation.Keys.VK_F12)
        time.sleep(3)
        win = automation.WindowControl(searchDepth=1,
                                       ClassName='ApplicationFrameWindow')
        control = win.WindowControl(searchDepth=1,
                                    ClassName='Windows.UI.Core.CoreWindow',
                                    searchWaitTime=100)
        # print(control)
        control = control.CustomControl(searchDepth=1,
                                        AutomationId='m_f12Docked')
        control = control.GroupControl(searchDepth=1)
        f12 = control.PaneControl(searchDepth=1)
        f12 = f12.PaneControl(searchDepth=1)
        f12 = f12.PaneControl(searchDepth=1, AutomationId='9')
        f12 = f12.PaneControl(searchDepth=1, Name='Network')
        toolbar = f12.ToolBarControl(searchDepth=1)
        self.button = toolbar.ButtonControl(searchDepth=1, Name='清除会话')
        self.button.Invoke()
        # button.Click()
        # contentFilter = toolbar.ButtonControl(searchDepth=1, Name = '内容类型筛选器')
        automation.SendKey(automation.Keys.VK_TAB)
        automation.SendKey(automation.Keys.VK_SPACE)
        automation.SendKey(automation.Keys.VK_DOWN)
        automation.SendKey(automation.Keys.VK_DOWN)
        automation.SendKey(automation.Keys.VK_DOWN)
        automation.SendKey(automation.Keys.VK_DOWN)
        automation.SendKey(automation.Keys.VK_DOWN)
        automation.SendKey(automation.Keys.VK_DOWN)
        automation.SendKey(automation.Keys.VK_SPACE)
        automation.SendKey(automation.Keys.VK_ESCAPE)

        self.groupControl = f12.GroupControl(
            searchDepth=1, Name='名称, 协议, 方法, 结果, 内容类型, 已接收, 时间, 发起程序, 开始时间,')
Esempio n. 6
0
 def senk_key(self, key_word):
     try:
         auto.SendKey(key_word)
         logger.info("按下_{}_键成功".format(key_word))
     except:
         logger.exception("按下_{}_键失败".format(key_word))
Esempio n. 7
0
def SendKey(key, waitTime=0.1, count=1):
    for t in range(count):
        uiautomation.SendKey(key, waitTime=waitTime)
Esempio n. 8
0
window_control = auto.WindowControl(searchDepth=3, Name="启动对话框")
auto.ButtonControl(searchDepth=4, Name="新建").Click()
num = 1
while num <= 1:
    z_number = str(random.randint(1, 40))
    z_path_name = os.path.join("C:\data", z_number + ".jpg")
    c_number = str(random.randint(1, 40))
    c_path_name = os.path.join("C:\data", c_number + ".jpg")
    patient_number = auto.EditControl(
        searchDepth=4, AutomationId="1022").GetValuePattern().Value
    name = "test_" + str(num)
    auto.EditControl(searchDepth=4,
                     AutomationId="1021").GetValuePattern().SetValue(name)
    auto.PaneControl(searchDepth=4,
                     AutomationId="1142").GetFirstChildControl().Click()
    auto.SendKey(0x25)
    auto.SendKey(0x0D)
    auto.EditControl(searchDepth=5,
                     AutomationId="1001").GetValuePattern().SetValue("候志明")
    auto.ButtonControl(searchDepth=4, Name="确定").Click()
    auto.ButtonControl(searchDepth=4, Name=" 请选择X光片 ").Click()
    time.sleep(1.5)
    auto.EditControl(searchDepth=6,
                     Name="文件名(N):").GetValuePattern().SetValue(c_path_name)
    auto.SendKey(0x0D)
    auto.Click(800, 500)
    auto.Click(500, 800)
    auto.ButtonControl(searchDepth=4,
                       Name=" 请选择X光片 ").GetNextSiblingControl().Click()
    time.sleep(1.5)
    auto.EditControl(searchDepth=6,