Python 通过pywinauto上的位置获取控制

Python 通过pywinauto上的位置获取控制,python,python-3.x,pywinauto,Python,Python 3.x,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

我在屏幕上有一个鼠标位置,例如(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.application导入应用程序
app=应用程序((backend=“uia”).start(“notepad.exe”)
dlg=应用程序顶部窗口()
硬编码的\u文件\u按钮\u rec=dlg.file.rectangle()#
给定鼠标位置=(10,10)
找到文件按钮=按位置搜索(应用程序,给定鼠标位置)
断言硬编码的\u文件\u按钮\u rec==找到的\u文件\u按钮。矩形()
pywinauto已经有了内置函数吗?在上,我找到了如何使用pywinauto迭代窗口中的所有控件。因此,通过迭代,我可以检查
controls[I].rectancle().top==10和controls[I].rectancle().left==10

正确的做法是什么?

方法
。从点(x,y)
正在开发中

解决方法如下:

以及在StackOverflow上:

任何元素的干净代码示例:

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()
等方法