我怎样才能得到窗口名称?[Python] [英] how can I get the window name? [Python]

查看:40
本文介绍了我怎样才能得到窗口名称?[Python]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取窗口名称?

我想制作一个脚本,其中有一些键盘事件,并且我希望它仅在窗口名称中包含某些内容(例如 Firefox)时发生.

I want to make a script where I have some keyboard event, and I want it to happens only if the window name has something in the name, like, Firefox.

我该怎么做?

最简单的方法

推荐答案

如果窗口名称"的意思是窗口 title",并且假设您在 hwnd<中有窗口句柄/code>,

If by "window name" you mean "window title", and assuming you have the window's handle in hwnd,

import win32gui
thetitle = win32gui.GetWindowText( hwnd )

您需要从 win32gui 和其他Python 的 Windows 扩展"nofollow noreferrer">这里,当然,并在您的机器上安装它们.

You need to download win32gui and the other "windows extensions for Python" from here, of course, and install them on your machine.

如果你的意思是别的,请澄清!

If you mean something else, please clarify!

这篇关于我怎样才能得到窗口名称?[Python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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