windows 桌面GUI自动化- 16.pywinauto 鼠标操作与滚动列表
前言
pywinauto 操作鼠标,滚动查看
鼠标点击操作
单击鼠标左键, coords 参数是点击的坐标位置
from pywinauto import mouse
# 单击鼠标左键
mouse.click(coords=(100,100))
鼠标右击
mouse.right_click(coords=(100,200))
鼠标双击
mouse.double_click(coords=(100,200))
鼠标长按,拖动,释放
mouse.press(coords=(200,400))
mouse.move(coords=(100, 0))
mouse.release(coords=(300,400))
鼠标滚轮操作
mouse.scroll(coords=(0, 0), wheel_dist=1)
鼠标中键单击指定的坐标
mouse.wheel_click(coords=(0, 0))
滚动列表
滚动微信聊天记录列表
from pywinauto import mouse
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
# 连接到wx
app = Application(backend='uia').connect(
path=r'C:\Program Files (x86)\Tencent\WeChat\WeChat.exe'
)
# 定位到主窗口
win = app.window(title="微信", class_name='WeChatMainWndForPC')
# 选择聊天窗口
loc = win.child_window(title="会话", control_type="List").rectangle()
print(loc)
# 滚动聊天窗口
mouse.scroll(coords=(loc.left+20, loc.top+30), wheel_dist=-2)