在 pywinauto 上按位置控制
Get control by position on pywinauto
我在屏幕上有一个鼠标位置,例如 (10, 10),我想将该位置转换为控件。我该怎么做?
示例:
from pywinauto.application import Application
app = Application((backend="uia").start("notepad.exe")
dlg = app.top_window()
hardcoded_file_button_rec = dlg.File.rectangle() #<RECT L10, T10, R40, B40>
given_mouse_position = (10, 10)
found_file_button = search_by_position(app, given_mouse_position)
assert hardcoded_file_button_rec == found_file_button.rectangle()
pywinauto 是否已经内置了这个功能?在 上,我发现了如何使用 pywinauto 遍历 window 中的所有控件。所以遍历它,我可以检查是否 controls[i].rectancle().top == 10 and controls[i].rectancle().left == 10
。
正确的做法是什么?
方法.from_point(x, y)
正在开发中。
解决方法在这里:issue #413。
以及 Whosebug:
任何元素的干净代码示例:
from ctypes.wintypes import tagPOINT
import pywinauto
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(x, y))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
wrapper = pywinauto.controls.uiawrapper.UIAWrapper(element)
wrapper
可能是您需要的,因为它是具有 .invoke()
等方法的可操作对象
我在屏幕上有一个鼠标位置,例如 (10, 10),我想将该位置转换为控件。我该怎么做?
示例:
from pywinauto.application import Application
app = Application((backend="uia").start("notepad.exe")
dlg = app.top_window()
hardcoded_file_button_rec = dlg.File.rectangle() #<RECT L10, T10, R40, B40>
given_mouse_position = (10, 10)
found_file_button = search_by_position(app, given_mouse_position)
assert hardcoded_file_button_rec == found_file_button.rectangle()
pywinauto 是否已经内置了这个功能?在 controls[i].rectancle().top == 10 and controls[i].rectancle().left == 10
。
正确的做法是什么?
方法.from_point(x, y)
正在开发中。
解决方法在这里:issue #413。
以及 Whosebug:
任何元素的干净代码示例:
from ctypes.wintypes import tagPOINT
import pywinauto
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(x, y))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
wrapper = pywinauto.controls.uiawrapper.UIAWrapper(element)
wrapper
可能是您需要的,因为它是具有 .invoke()
等方法的可操作对象