使用 Python 获取活动窗口 [英] Obtain Active window using Python

查看:124
本文介绍了使用 Python 获取活动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 python 在屏幕上获取活动窗口.

I would like to get the active window on the screen using python.

比如你输入用户名密码admin的路由器的管理界面

For example, the management interface of the router where you enter the username and password as admin

那个管理界面是我想要使用 python 来自动输入用户名和密码的内容.

That admin interface is what I want to capture using python to automate the entry of username and password.

为了做到这一点,我需要什么导入?

What imports would I require in order to do this?

推荐答案

在 windows 上,你可以使用 python for windows 扩展 (http://sourceforge.net/projects/pywin32/):

On windows, you can use the python for windows extensions (http://sourceforge.net/projects/pywin32/):

from win32gui import GetWindowText, GetForegroundWindow
print GetWindowText(GetForegroundWindow())

以下代码适用于 python 3:

Below code is for python 3:

from win32gui import GetWindowText, GetForegroundWindow
print(GetWindowText(GetForegroundWindow()))

(在 http://scott.sherrillmix.com/blog 上找到了这个/programmer/active-window-logger/)

这篇关于使用 Python 获取活动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆