简体   繁体   English

通过CPython / pywin32使用Windows UI Automation?

[英]Using Windows UI Automation via CPython/pywin32?

Based on a question I read and responded to on Reddit , I've been investigating using the relatively new Windows UI Automation framework via Python (and pywin32) to query custom widgets inside a Google Chrome window. 根据我在Reddit上阅读并回复问题 ,我一直在调查使用相对较新的Windows UI Automation框架(通过Python(和pywin32))来查询Google Chrome窗口中的自定义小部件。 UISpy shows me the control I'm interested in, but the naming conventions and lack of window classes make me believe the UI Automation framework is the only way to access it. UISpy向我展示了我感兴趣的控件,但命名约定和缺少窗口类让我相信UI自动化框架是访问它的唯一方法。 I was able to get as far as generating a COM stub for the UI Automation library via PythonWin and the Makepy utility, but couldn't actually instantiate the COM object. 我能够通过PythonWin和Makepy实用程序为UI自动化库生成COM存根,但实际上无法实例化COM对象。 I don't have a lot of experience with COM, outside of following along in Mark Hammond's "Python Programming on Win32" to drive Excel via COM with Python. 我没有很多COM经验,除了跟随Mark Hammond的“Win32上的Python编程”,通过COM用Python驱动Excel。 I found an article describing how to instantiate the COM object from C/C++ but I wasn't able to get much from it. 我发现了一篇描述如何从C / C ++实例化COM对象文章,但我无法从中获得太多。

I think I can follow along with the API documentation if I can just figure out how to instantiate the object. 如果我能弄清楚如何实例化对象,我想我可以按照API文档进行操作。

You can use the awesome comtypes package to easily use the IUIAutomation COM interface from CPython scripts. 您可以使用awesome comtypes包轻松使用CPython脚本中的IUIAutomation COM接口。

Here's a very simple demo I wrote: 这是我写的一个非常简单的演示:

https://github.com/billagee/test-polyglot/blob/master/printDesktopUiaElementName/ms-ui-automation-com-api/python/comtypes/print_desktop_uia_element_name.py https://github.com/billagee/test-polyglot/blob/master/printDesktopUiaElementName/ms-ui-automation-com-api/python/comtypes/print_desktop_uia_element_name.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM