python+autoit用法

python+autoit用法

2023年7月9日发(作者:)

python+autoit⽤法⼀、⾃⼰封装的⼀些使⽤到的autoit库import autoitclass MouseControl(object): ''' AutoIt⿏标相关操作 ''' def __init__(self): ''' Constructor '''

def click(self, title, text, x, y, button="main", clicks=1): ''' :description 执⾏⿏标点击操作 ''' pos = _get_pos(title, text=text) _click(button, x + pos[0], y + pos[1], clicks=clicks)

def move(self, title, text, x, y): ''' :description 移动⿏标指针 ''' pos = _get_pos(title, text=text) _move(x + pos[0], y + pos[1])

def drag(self, title, text, x1, y1, x2, y2): ''' :description 执⾏⿏标拖拽操作 ''' pos = _get_pos(title, text=text) _click_drag(x1 + pos[0], y1 + pos[1], x2 + pos[0], y2 + pos[1])

def wheel(self, direction="up"): ''' :description 产⽣向上或向下滚动⿏标滚轮事件.仅⽀持NT/2000/XP及更⾼. ''' _wheel(direction)rt autoitclass ProcessControl(object): ''' AutoIt进程相关操作 '''

def __init__(self, processName): ''' Constructor ''' sName = processName

def close(self): ''' :description 终⽌某个进程 :return 1:成功; 0:失败. ''' return s_close(sName)

def exists(self): ''' :description 检查指定进程是否存在 :return PID:成功; 0:进程不存在. ''' return s_exists(sName)processControlimport autoitclass WinControl(object): ''' AutoIt窗⼝相关操作 ''' def __init__(self, title, text=''): ''' Constructor ''' = title = text

def activate(self): ''' :description 激活指定的窗⼝(设置焦点到该窗⼝,使其成为活动窗⼝). :return PID:窗⼝存在; 0:窗⼝不存在. '''

return _activate(, text=)

def close(self): ''' :description 关闭指定窗⼝. :return 1:成功; 0:窗⼝不存在. '''

return _close(, text=)

def exists(self): ''' :description 检查指定的窗⼝是否存在. :return 1:窗⼝存在; 0:窗⼝不存在. ''' return _exists(, text=)

def getPos(self): ''' :description 获取指定窗⼝的坐标位置和⼤⼩等属性. :return Returns left, top, right, bottom (x1,y1,x2,y2) ''' return _get_pos(, text=) def getProcess(self): ''' :description 获取指定窗⼝关联的进程ID(PID). :return PID:成功, -1:失败. ''' return _get_process(, text=)

def getText(self, buf_size=256): ''' :description 获取指定窗⼝中的⽂本. :return 指定窗⼝⾥包含的⽂本:成功; 0:失败(没有匹配的窗⼝). '''

return _get_text(, buf_size, text=)

def kill(self): ''' :description 强⾏关闭指定窗⼝. :return 1:⽆论成功失败. '''

return _kill(, text=)

def move(self, x, y, width, height): ''' :description 移动指定的窗⼝或调整窗⼝的⼤⼩. :return PID:成功, 0:失败(窗⼝不存在). ''' return _move(, x, y, width, height, text=)

def setState(self, flag): ''' :description 显⽰,隐藏,最⼩化,最⼤化或还原⼀个窗⼝. :param flag: The "show" flag of the executed program:= 显⽰= 最⼩化/隐藏= 最⼤化= 还原 :return 1:成功, 0:失败(窗⼝不存在). ''' return _set_state(, flag, text=)

def wait(self, timeout=5): ''' :description 暂停脚本的执⾏直⾄指定窗⼝存在(出现)为⽌. timeout 单位为秒. :return PID:成功, 0:失败(超时). ''' return _wait(, timeout, text=)

def waitActive(self, timeout=5): ''' :description 暂停脚本的执⾏直⾄指定窗⼝被激活(成为活动状态)为⽌. timeout 单位为秒. :return PID:成功, 0:失败(超时). ''' return _wait_active(, timeout, text=)

def waitClose(self, timeout=5): ''' :description 暂停脚本的执⾏直⾄所指定窗⼝不再存在为⽌. timeout 单位为秒. :return 1:成功, 0:失败(超时). ''' return _wait_close(, timeout, text=)

def waitNotActive(self, timeout=5): ''' :description 暂停脚本的执⾏直⾄指定窗⼝不是激活状态为⽌. timeout 单位为秒. :return 1:成功, 0:失败(超时). ''' return _wait_not_active(, timeout, text=)

def controlClick(self, control, button="main", clicks=1): ''' :description 向指定控件发送⿏标点击命令. ''' l_click(, control, text=, button=button, clicks=clicks)

def controlCommand(self, control, command, extra="", buf_size=256): ''' :description 向指定控件发送命令. :param command, extra: :return "IsVisible", "" 1:可见; 0:不可见 "IsEnabled", "" 1:可⽤; 0:禁⽤ "ShowDropDown", "" 弹出/下拉 组合框(ComboBox)的列表. "HideDropDown", "" 收回/隐藏 组合框(ComboBox)的列表. "AddString", "string" 在 ListBox 或 ComboBox 的编辑框后⾯附加指定字符串. "DelString", 出现次序 删除在 ListBox 或 ComboBox 的编辑框中指定的字符串(从0开始). "FindString", "string" 返回在 ListBox 或 ComboBox 的编辑框中与指定字符串匹配项⽬的出现次序(从0开始). "SetCurrentSelection", 出现次序 通过指定出现次序(从0开始)把 ListBox 或 ComboBox 的当前选择项设为指定的项⽬. "SelectString","string" 通过指定字符串把 ListBox 或 ComboBox 的当前选择项设为匹配字符串的项⽬. "IsChecked", "" 若⽬标按钮(复选框/单选框)被选中则返回值为1,否则为0. "Check", "" 使⽬标按钮(复选框/单选框)变为选中状态. "UnCheck", "" 使⽬标按钮(复选框/单选框)变为⾮选中状态. "GetCurrentLine", "" 返回在⽬标编辑框中插⼊符(caret,光标)的所在⾏号. "GetCurrentCol", "" 返回在⽬标编辑框中插⼊符(caret,光标)的所在列号. "GetCurrentSelection", "" 返回 ListBox 或 ComboBox 控件当前选中的项⽬名. "GetLineCount", "" 返回⽬标编辑框中的总⾏数. "GetLine", ⾏号 返回⽬标编辑框中指定⾏的⽂本内容. "GetSelected", "" 返回⽬标编辑框中的(⽤户⽤⿏标或其它⽅式)选定的⽂本. "EditPaste", 'string' 在⽬标编辑框中插⼊符(caret)所在位置后插⼊指定字符串. "CurrentTab", "" 返回在 SysTabControl32 控件中当前显⽰的标签编号(从1开始). "TabRight", "" 使 SysTabControl32 控件切换到(右边的)下⼀个标签. "TabLeft", "" 使 SysTabControl32 控件切换到(左边的)下⼀个标签.

"SendCommandID", 命令 ID 模拟 WM_COMMAND 消息. 通常⽤于 ToolbarWindow32 控件 - 使⽤Au3Info的⼯具栏标签得到命令ID. '''

return l_command(, control, command, buf_size, text=, extra=extra)

def controlListView(self, control, command, extra1, extra2="", buf_size=256): ''' :description 向指定的 ListView32 控件发送命令. :param command, extra1, extra2: :return "DeSelect", 从[, 到] 取消选定从"从"开始直到"到"的⼀个或多个项⽬.

"FindItem", "搜索字符串" [, ⼦项⽬] 返回与给定字符串匹配的项⽬的位置.若未找到指定字符串则返回值为 -1.

"GetItemCount" 返回列表中项⽬的数量.

"GetSelected" [, 选项] 返回当前选中项⽬的位置.若 选项=0(默认)则只返回选中的第⼀个项⽬;若 选项=1 则返回由竖线"|"作为分隔符的所有选中项⽬,例如:"0|3|4|10".若没有选中任何项⽬则返回⼀个空字符串"". "GetSelectedCount" 返回选中项⽬的数量.

"GetSubItemCount" 返回⼦项⽬的数量.

"GetText", 项⽬, ⼦项⽬ 返回指定项⽬/⼦项⽬的⽂本.

"IsSelected", 项⽬ 若指定项⽬被选中则返回值为1,否则返回值为0.

"Select", 从[, 到] 选中⼀个或多个项⽬(请参考第⼀个命令).

"SelectAll" 选中所有项⽬.

"SelectClear" 取消所有项⽬的选中状态.

"SelectInvert" 切换当前的选中状态.

"ViewChange", "视图" 切换当前的视图.可⽤的视图包括"list"(列表),"details"(详细信息),"smallicons"(⼩图标),"largeicons"(⼤图标).

'''

return l_list_view(, control, command, buf_size, text=, extra1=extra1, extra2=extra2)

def controlDisable(self, control): ''' :description 禁⽤或使某控件变成灰⾊不可⽤状态. :return 1:成功; 0:失败. '''

return l_disable(, control, text=)

def controlEnable(self, control): ''' :description 使灰⾊按钮/控件变为"可⽤"状态. :return 1:成功; 0:失败. '''

return l_enable(, control, text=)

def controlFocus(self, control): ''' :description 设置输⼊焦点到指定窗⼝的某个控件上. :return 1:成功; 0:失败. '''

return l_focus(, control, text=)

def controlGetText(self, control): ''' :description 获取指定控件上的⽂本. :return ⽂本内容:成功; 空:失败. '''

return l_get_text(, control, text=)

def controlSend(self, control, send_text, mode=0 ):

''' :description 向指定的控件发送字符串. :param mode: 0:按特殊字符含义发送(默认); 1:原样发送. :return 1:成功; 0:失败(窗⼝/控件未找到). '''

return l_send(, control, send_text, mode, text=)

def controlSetText(self, control, control_text): ''' :description 修改指定控件的⽂本. :return 1:成功; 0:失败(窗⼝/控件未找到). '''

return l_set_text(, control, control_text, text=)

def controlTreeView(self, control, command, extra, buf_size=256): ''' :description 发送⼀个命令到 TreeView32 控件.(⼦节点不好⽤*) :param command, extra :return "Check", "项⽬" 选中⼀个项⽬ (如果项⽬⽀持选中,这⾥指项⽬带有选择框).

"Collapse", "项⽬" 折叠⼀个项⽬节点,使它隐藏它的⼦项⽬.

"Exists", "项⽬" *都返回1* 如果项⽬存在返回 1,否则返回 0.

"Expand", "项⽬" 展开⼀个项⽬节点,使它显⽰它的⼦项⽬.

"GetItemCount", "项⽬" 返回所选项⽬的⼦项⽬数量.

"GetSelected" [, 使⽤索引] 返回当前所选项⽬的⽂本参考信息(如果使⽤索引设置为1将会返回所选项⽬索引位置).

"GetText", "项⽬" 返回项⽬⽂本.

"IsChecked" 返回项⽬选中状态. 1:被选中, 0:未被选中, -1:没要选择框.

"Select", "项⽬" 选择⼀个项⽬.

"Uncheck", "项⽬" 取消项⽬选中状态 (如果项⽬⽀持选中,这⾥指项⽬带有选择框).

'''

return l_tree_view(, control, command, text=, buf_size=buf_size, extra=extra)

def statusbarGetText(self, part=1, buf_size=256): ''' :description 获取标准状态栏控件的⽂本. :return ⽂本内容:成功; 空字符串:失败(⽆法读取⽂本). '''

return bar_get_text(, , part, buf_size)

winControl有些控件操作没有原⽣的autoit⽀持的好,⽐如对树控件的操作,经常会有问题,如果遇到出现问题只能再换autoit写au3⽂件直接运⾏了......⼆、遇到的坑1. 在等待窗⼝出现时,⽐较了try和while⽅法,觉得还是while⽅法⽐较⽅⾯和好⽤,尤其是你将等待出现的窗⼝可能有好⼏种不同的窗⼝时,⽤while+if就很⽅便。def isclientupdate(): '''判断包是否需要升级''' w_clientupdate = trol(title_update) w_clientupdate_choice = trol(title_choice) flag = True count = 0 while flag: if w_(): clientupdate() flag = False elif w_clientupdate_(): w_clientupdate_lClick('Button2') clientupdate() flag = False else: (1) count += 1 if count == 5: clientlogin() flag = False

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1688898566a181957.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信