You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现按住鼠标左键拖动选择表格内多个按钮式单元格

实现表格按钮的鼠标拖拽选择功能

我需要实现点击按钮A1,按住左键拖动到A5,以此选中A1到A5这5个字段。表格列从A到G、行从1到12,每个单元格都是按钮,需要一个能选择指定数量字段的函数。

尝试过的无效方法

  • 使用控件的hold和release方法,未生效:

    window.child_window(auto_id="A1", control_type="Custom", found_index=0).hold(button='left')
    window.child_window(auto_id="A5", control_type="Custom", found_index=0).release(button='left')
    
  • 尝试DragMouseInput方法,仍然无效:

    A1 = window.child_window(auto_id="A1", control_type="Custom", found_index=0)
    A5 = window.child_window(auto_id="A5", control_type="Custom", found_index=0)
    window.DragMouseInput("left", A1.Rectangle().mid_point(), A5.Rectangle().mid_point())
    

解决方法

通过pyautogui模拟真实的鼠标拖拽流程,先定位到目标按钮的中点坐标,再执行按下、拖动、释放的动作:

cell1 = window.child_window(auto_id=start_well, control_type="Custom")
cell2 = window.child_window(auto_id=end_well, control_type="Custom")

start_coords = cell2.rectangle().mid_point()
end_coords = cell1.rectangle().mid_point()

pyautogui.moveTo(start_coords[0], start_coords[1], duration=0.5)
pyautogui.mouseDown()

pyautogui.moveTo(end_coords[0], end_coords[1], duration=2)
pyautogui.mouseUp()

内容的提问来源于stack exchange,提问作者TestAutomation

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 12:03:27