xbot.win32.Image

概述

Image接口主要是对图像的一些常规处理,如等待图像出现/消失、点击图像、将鼠标移动到图像上等,图像来源主要有两种

  • 指定窗口

  • 当前屏幕

详情

wait_appear

在当前屏幕中等待与图像选择器匹配的图片出现

wait_appear(image_selectors, * , wait_all=False, timeout=20)

参数

  • image_selectors:图像选择器, 支持以下格式:

    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器

    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组

  • wait_all:是否等待全部目标图片出现后在执行,默认值为False不等待全部图片出现

  • timeout:等待目标图片出现的超时时间,默认时间为20s

返回值

  • bool:在指定延迟时间内如果目标元素出现则返回True,否则返回False

实列1

在当前屏幕中等待与图像选择器 图像1 匹配的图像出现

from xbot import win32

def main(args):
    appear = win32.image.wait_appear("图像1")

wait_appear_from_window

在当前激活的窗口中等待与图像选择器匹配的图片出现

wait_appear_from_window(hWnd, image_selectors, * , wait_all=False, timeout=20)

参数

  • hWnd:目标窗口的句柄, 可通过窗口对象 xbot.win32.window.Win32Window 的 hWnd 属性获得

  • image_selectors:图像选择器, 支持以下格式:

    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器

    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组

  • wait_all:是否等待全部目标图片出现后在执行, 默认值为False不等待全部图片出现

  • timeout:等待目标图片出现的超时时间, 默认时间为20s

返回值

  • bool:在指定延迟时间内如果目标元素出现则返回True, 否则返回False

实列1

在当前激活的窗口中等待与图像选择器 图像1 匹配的图像出现

from xbot import win32
from . import package 

def main(args):
    hWnd = win32.get('新建文本').hWnd
    appear = win32.image.wait_appear_from_window(hWnd, "图像1")

wait_disappear

在当前屏幕中等待与图像选择器匹配的图片消失

wait_disappear(image_selectors, * , wait_all=False, timeout=20)

参数

  • image_selectors:图像选择器, 支持以下格式:
    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • wait_all:是否等待全部目标图片消失后在执行,默认值为False不等待全部图片消失
  • timeout:等待目标图片消失的超时时间,默认时间为20s

返回值

  • bool:在指定延迟时间内如果目标元素出现则返回True,否则返回False

实列1

在当前屏幕中等待与图像选择器 图像1 匹配的图像消失

from xbot import win32

def main(args):
    appear = win32.image.wait_disappear('图像1')

wait_disappear_from_window

在当前激活的窗口中等待与图像选择器匹配的图片消失

wait_disappear_from_window(hWnd, image_selectors, * , wait_all=False, timeout=20)

参数

  • hWnd:目标窗口的句柄, 可通过窗口对象 xbot.win32.window.Win32Window 的 hWnd 属性获得

  • image_selectors:图像选择器, 支持以下格式:

    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • wait_all:是否等待全部目标图片消失后在执行, 默认值为False不等待全部图片消失
  • timeout:等待目标图片消失的超时时间, 默认时间为20s

返回值

  • bool:在指定延迟时间内如果目标元素出现则返回True,否则返回False

实列1

在当前激活的窗口中等待与图像选择器 图像1 匹配的图像消失

from xbot import win32

def main(args):
    hWnd = win32.get('新建文本').hWnd
    appear = win32.image.wait_disappear_from_window(hWnd, "图像1")

hover

在当前屏幕上查找与图像选择器匹配的图片并将鼠标悬停在上面

hover(image_selectors, * , anchor=None)

参数

  • image_selectors:图像选择器, 支持以下格式:
    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • anchor:锚点,鼠标点击元素的位置以及偏移量元组,默认值为 None,为 None 时默认点击目标中心且无偏移量,参数结构如下:
    • sudoku_part:鼠标悬停的位置, 默认悬停在中心
      • 'topLeft':悬停左上角
      • 'topCenter':悬停在上中部
      • 'topRight':悬停在右上角
      • 'middleLeft':悬停在左中部
      • 'middleCenter':悬停在中心
      • 'middleRight':悬停在右中部
      • 'bottomLeft':悬停左下角
      • 'bottomCenter':悬停在下中部
      • 'bottomRight':悬停在右下角
    • offset_x:鼠标位置的水平偏移量
    • offset_y':鼠标位置的垂直偏移量

返回值

实列1

在当前屏幕中查找与图像选择器 图像1 匹配的图像出现并将鼠标悬停在目标图像的中间,鼠标坐标的水平和垂直偏移量都为100

from xbot import win32
from .package import *

def main(args):
    win32.image.hover('图像1', anchor=('middleCenter', 100, 100))

hover_on_window

在当前屏幕上查找与图像选择器匹配的图片并将鼠标悬停在上面

hover_on_window(hWnd, image_selectors, * , anchor=None)

参数

  • hWnd:目标窗口的句柄, 可通过窗口对象 xbot.win32.window.Win32Window 的 hWnd 属性获得

  • image_selectors:图像选择器, 支持以下格式:

    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • anchor:锚点,鼠标点击元素的位置以及偏移量元组,默认值为 None,为 None 时默认点击目标中心且无偏移量,参数结构如下:
    • sudoku_part:鼠标悬停的位置, 默认悬停在中心
      • 'topLeft':悬停左上角
      • 'topCenter':悬停在上中部
      • 'topRight':悬停在右上角
      • 'middleLeft':悬停在左中部
      • 'middleCenter':悬停在中心
      • 'middleRight':悬停在右中部
      • 'bottomLeft':悬停左下角
      • 'bottomCenter':悬停在下中部
      • 'bottomRight':悬停在右下角
    • offset_x:鼠标位置的水平偏移量
    • offset_y':鼠标位置的垂直偏移量

返回值

实列1

在当前激活的窗口中查找与图像选择器 图像1 匹配的图像出现并将鼠标悬停在目标图像的中间,鼠标坐标的水平和垂直偏移量都为100

from xbot import win32

def main(args):
    hWnd = win32.get('新建文本').hWnd
    win32.image.hover_on_window(hWnd, '图像1', anchor=('middleCenter', 100, 100))

click

在这当前屏幕上查找与图像选择器相似的图像并单击

click(image_selectors, * , anchor=None, button='left', keys='none', move_mouse=True)

参数

  • image_selectors:图像选择器, 支持以下格式:

    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • anchor:锚点,鼠标点击元素的位置以及偏移量元组,可为 None,默认值为 None,为 None 时默认点击目 标中心且无偏移量,参数结构如下:
    • sudoku_part:鼠标悬停的位置, 默认悬停在中心
      • 'topLeft':悬停左上角
      • 'topCenter':悬停在上中部
      • 'topRight':悬停在右上角
      • 'middleLeft':悬停在左中部
      • 'middleCenter':悬停在中心
      • 'middleRight':悬停在右中部
      • 'bottomLeft':悬停左下角
      • 'bottomCenter':悬停在下中部
      • 'bottomRight':悬停在右下角
    • offset_x:鼠标位置的水平偏移量
    • offset_y':鼠标位置的垂直偏移量
  • button:鼠标点击时按下的按键,默认为鼠标左键
    • 'left':鼠标左键
    • 'right':鼠标右键
  • keys:鼠标点击时使用键盘辅助按键,可为空,默认为空
    • 'none':不使用键盘辅助按键
    • 'alt':使用键盘Alt键作为辅助按键
    • 'ctrl':使用键盘Ctrl键作为辅助按键
    • 'shift':使用键盘Shift键作为辅助按键
    • 'win':使用Win(窗口)键作为辅助按键
    • move_mouse:是否显示鼠标移动轨迹,,默认值为True显示鼠标移动轨迹

返回值

实列1

在当前屏幕中查找与图像选择器 图像1 匹配的图像出现并用鼠标左键点击图像的中间,鼠标点击坐标的水平和垂直偏移量都为100,点击同时按下键盘 Alt 键,移动鼠标时显示鼠标移动轨迹

from xbot import win32

def main(args):
    win32.image.click('图像1', anchor=('middleCenter', 100, 100), 
                      button='left', keys='alt', move_mouse=True)

click_on_window

在这当前激活的窗口中查找与图像选择器相似的图像并单击

click_on_window(hWnd, image_selectors, * , anchor=None, button='left', keys='none', move_mouse=True)

参数:

  • hWnd:目标窗口的句柄, 可通过窗口对象 xbot.win32.window.Win32Window 的 hWnd 属性获得

  • image_selectors:图像选择器, 支持以下格式:

    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • anchor:锚点,鼠标点击元素的位置以及偏移量元组,可为 None,默认值为 None,为 None 时默认点击目标中心且无偏移量,参数结构如下:
    • sudoku_part:鼠标悬停的位置, 默认悬停在中心
      • 'topLeft':悬停左上角
      • 'topCenter':悬停在上中部
      • 'topRight':悬停在右上角
      • 'middleLeft':悬停在左中部
      • 'middleCenter':悬停在中心
      • 'middleRight':悬停在右中部
      • 'bottomLeft':悬停左下角
      • 'bottomCenter':悬停在下中部
      • 'bottomRight':悬停在右下角
    • offset_x:鼠标位置的水平偏移量
    • offset_y':鼠标位置的垂直偏移量
  • button:鼠标点击时按下的按键,默认为鼠标左键
    • 'left':鼠标左键
    • 'right':鼠标右键
  • keys:鼠标点击时使用键盘辅助按键,可为空,默认为空
    • 'none':不使用键盘辅助按键
    • 'alt':使用键盘Alt键作为辅助按键
    • 'ctrl':使用键盘Ctrl键作为辅助按键
    • 'shift':使用键盘Shift键作为辅助按键
    • 'win':使用Win(窗口)键作为辅助按键
    • move_mouse:是否显示鼠标移动轨迹,,默认值为True显示鼠标移动轨迹

返回值

实列1

在当前激活的窗口中查找与图像选择器 图像1 匹配的图像出现并用鼠标左键点击图像的中间,鼠标点击坐标的水平和垂直偏移量都为100,点击同时按下键盘 Alt 键,移动鼠标时显示鼠标移动轨迹

from xbot import win32
from .package import *

def main(args):
    hWnd = win32.get('新建文本').hWnd
    win32.image.click_on_window(hWnd, '图像1', anchor=('middleCenter', 100, 100),
                                button='left', keys='alt', move_mouse=True)

dblclick

在这当前屏幕上查找与图像选择器相似的图像并双击

dblclick(image_selectors, * , anchor=None, move_mouse=True)

参数

  • image_selectors:图像选择器, 支持以下格式:
    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
  • anchor:锚点,鼠标点击元素的位置以及偏移量元组,可为 None,默认值为 None,为 None 时默认点击目标中心且无偏移量,参数结构如下:
    • sudoku_part:鼠标悬停的位置, 默认悬停在中心
      • 'topLeft':悬停左上角
      • 'topCenter':悬停在上中部
      • 'topRight':悬停在右上角
      • 'middleLeft':悬停在左中部
      • 'middleCenter':悬停在中心
      • 'middleRight':悬停在右中部
      • 'bottomLeft':悬停左下角
      • 'bottomCenter':悬停在下中部
      • 'bottomRight':悬停在右下角
    • offset_x:鼠标位置的水平偏移量
    • offset_y':鼠标位置的垂直偏移量
  • move_mouse:是否显示鼠标移动轨迹,,默认值为True显示鼠标移动轨迹

返回值

实列1

在当前屏幕中查找与图像选择器 图像1 匹配的图像出现并用鼠标双击图像的中间,鼠标双击坐标的水平和垂直偏移量都为100,移动鼠标时显示鼠标移动轨迹

from xbot import win32

def main(args):
    win32.image.dblclick('图像1', anchor=('middleCenter', 100, 100), move_mouse=True)

dblclick_on_window

在这当前激活的窗口中查找与图像选择器相似的图像并双击

dblclick_on_window(hWnd, image_selectors, * , anchor=None, move_mouse=True)

参数

  • hWnd:目标窗口的句柄, 可通过窗口对象 xbot.win32.window.Win32Window 的 hWnd 属性获得
  • image_selectors:图像选择器, 支持以下格式:
    • 'img' 或 package.image_selector('img'),获取名称为img的图像选择器
    • ['img1', 'img2'] 或 [package.image_selector('img1'),package.image_selector('img2')], 获取名称为img1和img2的图像选择器组
    • anchor:锚点,鼠标点击元素的位置以及偏移量元组,可为 None,默认值为 None,为 None 时默认点击目标中心且无偏移量,参数结构如下:
    • sudoku_part:鼠标悬停的位置, 默认悬停在中心
      • 'topLeft':悬停左上角
      • 'topCenter':悬停在上中部
      • 'topRight':悬停在右上角
      • 'middleLeft':悬停在左中部
      • 'middleCenter':悬停在中心
      • 'middleRight':悬停在右中部
      • 'bottomLeft':悬停左下角
      • 'bottomCenter':悬停在下中部
      • 'bottomRight':悬停在右下角
    • offset_x:鼠标位置的水平偏移量
    • offset_y':鼠标位置的垂直偏移量
  • move_mouse:是否显示鼠标移动轨迹,,默认值为True显示鼠标移动轨迹

返回值

实列1

在当前激活的窗口中查找与图像选择器 图像1 匹配的图像出现并用鼠标双击图像的中间,鼠标双击坐标的水平和垂直偏移量都为100,移动鼠标时显示鼠标移动轨迹

from xbot import win32
def main(args):
    hWnd = win32.get('新建文件').hWnd
    win32.image.dblclick_on_window(hWnd, '图像1', anchor=('middleCenter', 100, 100),
                                   move_mouse=True)
问题没有解决?去社区提问 all right reserved,powered by Gitbook

results matching ""

    No results matching ""