Pywinauto 中的 DragMouse 命令

DragMouse command in Pywinauto

我正在使用 pywinauto 并且必须从一个应用程序中复制一个词,该应用程序在 PrintControlIdentifiers() 命令上没有检索到任何值。我的想法是使用 DragMouse 命令将鼠标从文本的开头拖动到文本的结尾,然后使用 Ctrl + C 命令。

我在我的应用程序中使用了以下命令:

window1.DragMouse(button='left', pressed='',press_coords=(256,0),release_coords=(256,800))

但这不起作用,也没有抛出任何错误消息。请告诉我在哪里可以找到有关 DragMouse 的更多示例。

如果 DragMouseInput 对您不起作用,我可以建议一个解决方法。代码可能看起来像这样(只是一个原型,未经测试):

 from pywinauto import clipboard

 app.Window.Control.TypeKeys('^a^c') # Ctrl+A, Ctrl+C
 full_str = clipboard.GetData()
 start_index = full_str.find(substring)
 app.Window.Control.TypeKeys('{HOME}{RIGHT %d}+{RIGHT %d}^c' % (start_index, len(substring)))
 # ^ is Ctrl, + is Shift

这种方法不依赖于更能抵抗屏幕分辨率变化的坐标。

要导航到控件(如果它不在键盘焦点中),您可以使用 {TAB} 键别名(顺便说一句,{TAB 3} == {TAB}{TAB}{TAB})。