滚动与窗口

滚动与翻页

auto.page_down(times=3)
auto.page_up(times=2)
auto.scroll(delta=-120, x=400, y=300)    # 滚轮,delta 负值为向下
auto.sleep(0.5)                          # 链式等待

API 参考

滚动与等待

✨page_down / page_up

翻页。

auto.page_down(times=3, ctrl=ctrl)
auto.page_up(times=2, ctrl=ctrl)

参数

参数名类型默认值描述
timesint1翻页次数
ctrlControlNone聚焦控件
modestrNone操作模式

返回值

  • 类型:WinAuto

✨scroll

滚轮滚动。

auto.scroll(delta=-120, x=400, y=300)

参数

参数名类型默认值描述
deltaint-120滚轮量;负值为向下
xint0屏幕坐标 X;默认窗口中心
yint0屏幕坐标 Y

返回值

  • 类型:WinAuto

✨sleep

链式等待。

auto.sleep(0.5)

参数

参数名类型默认值描述
secondsfloat等待秒数

返回值

  • 类型:WinAuto

窗口与弹窗

✨set_window_rect

设置绑定窗口的位置与尺寸(屏幕坐标)。若要在创建 WinAuto 之前调整窗口,请直接用 force_set_window_rect(见下方示例)。

auto.set_window_rect(0, 0, width=1100, height=800)
auto.set_window_rect(120, 48, width=986, height=2120, hwnd=725610)

绑定流程中更推荐(写在 auto = WinAuto(...) 之前):

from chatautox.utils.win32 import force_set_window_rect

hwnd = WinAuto.find_hwnd(WIN_CLASS, WIN_TITLE_KEY)
force_set_window_rect(hwnd, 0, 0, 1100, 2120, activate=False)
auto = WinAuto(hwnd, mode='mouse')
time.sleep(0.3)

参数

参数名类型默认值描述
leftint窗口左上角屏幕 X
topint窗口左上角屏幕 Y
widthint宽度(至少 50)
heightint高度(至少 50)
hwndintNone目标 HWND,默认 self.hwnd
activateboolFalse是否激活窗口

返回值

  • 类型:WinAuto

✨activate

激活窗口到前台。

auto.activate()
popup.activate(popup_hwnd)

参数

参数名类型默认值描述
hwndintNone目标 HWND,默认 self.hwnd

返回值

  • 类型:WinAuto

✨close_window

关闭窗口(WM_CLOSE),可选 Esc 补充。

auto.close_window()                    # 关闭当前绑定窗口
auto.close_window(popup_hwnd)          # 关闭指定 HWND
auto.close_window(esc=True)            # WM_CLOSE 后再发 Esc

参数

参数名类型默认值描述
hwndintNone目标 HWND,默认 self.hwnd
escboolFalse是否额外发送 Esc

返回值

  • 类型:WinAuto

✨snapshot_popups

点击前快照已有弹窗 HWND 集合。

before = auto.snapshot_popups(['Chrome_WidgetWin_0'])

参数

参数名类型默认值描述
class_nameslist[str]要监控的 Win32 类名列表

返回值

  • 类型:frozenset[int]

✨wait_popup

差集等待新弹窗出现。

popup_hwnd = auto.wait_popup(['Chrome_WidgetWin_0'], before, timeout=5.0)

参数

参数名类型默认值描述
class_nameslist[str]要监控的 Win32 类名列表
beforefrozenset[int]snapshot_popups 的返回值
timeoutfloat5.0超时(秒)
pidintNone可选,限制进程

返回值

  • 类型:int
  • 描述:新弹窗 HWND;超时返回 0

✨find_descendant_hwnd

按 Win32 类名查找子窗口,如 Chrome_RenderWidgetHostHWND

child = auto.find_descendant_hwnd('Chrome_RenderWidgetHostHWND')
print('子窗口 HWND:', child)

参数

参数名类型默认值描述
class_namestr子窗 ClassName
root_hwndintNone根 HWND,默认 self.hwnd

返回值

  • 类型:int

✨focus_descendant

查找子窗口并 SetFocus。

child = auto.focus_descendant('Chrome_RenderWidgetHostHWND')
print('已聚焦子 HWND:', child)

参数

参数名类型默认值描述
class_namestr'Chrome_RenderWidgetHostHWND'子窗 ClassName

返回值

  • 类型:int
  • 描述:子 HWND
before = auto.snapshot_popups(['Chrome_WidgetWin_0'])
auto.click_bubble(note_msg, mode='uia')
popup_hwnd = auto.wait_popup(['Chrome_WidgetWin_0'], before, timeout=5.0)
popup = WinAuto(popup_hwnd, mode='uia')
body = popup.find(ctrl_type='DocumentControl', aid='RootWebArea', depth=9)
result = popup.copy_content(body, mode='uia')

上一页剪贴板下一页列表与会话