windows 获取活动窗口的名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/608809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:06:32  来源:igfitidea点击:

Getting the name of the active window

pythonwindows

提问by Christian

I want to write a python script on Windows that saves the title of the program that the user uses at a given time like the http://www.rescuetime.com. I don't want to use rescuetime because of privacy consideration but instead write a script that does something similar myself to capture data about how much I use my computer.

我想在 Windows 上编写一个 python 脚本来保存用户在给定时间使用的程序的标题,如http://www.rescuetime.com。出于隐私考虑,我不想使用救援时间,而是编写一个脚本来执行类似的操作,以捕获有关我使用计算机的次数的数据。

Is there some easy command that I can use to read that information?

是否有一些简单的命令可以用来读取该信息?

回答by ólafur Waage

From daniweb

来自 daniweb

  import win32gui
  w=win32gui
  w.GetWindowText (w.GetForegroundWindow())