简体   繁体   English

在Python中获取活动窗口

[英]get active window in python

I'm bored and just making something for the heck of it in Python. 我很无聊,只是用Python做些什么。 I saw someone typing with spaces between all their letters and decided to make a python script that does this. 我看到有人在所有字母之间输入空格,然后决定制作一个可以执行此操作的python脚本。 It was pretty easy, but then I wanted to take it a step further, because copy/pasting from console takes time, so I want to have this script put spaces after every keyboard press but only when I have Discord as the active window. 这很简单,但是后来我想更进一步,因为从控制台进行复制/粘贴需要时间,所以我想让此脚本在每次按下键盘后都放空格,但仅当我将Discord作为活动窗口时才放。 The only things I could find that could give you the active window are from 5-15 years ago, and are all outdated. 我发现可以为您提供活动窗口的唯一内容是5到15年前,并且都过时了。 They say use win32gui, and I pipinstalled it, but it doesn't seem to work. 他们说使用win32gui,并且我pipinstall了它,但是似乎不起作用。

EDIT: For clarification, I ran "pip install win32gui" and it installed, I opened a python shell and typed "import win32gui" and it said no such module I looked through the modules and found win32 and according to the help command win32gui is part of its package, so I tried win32.win32gui and it says there's no such attribute 编辑:为澄清起见,我运行了“ pip install win32gui”并安装了它,我打开了一个python shell并键入了“ import win32gui”,它说没有这样的模块,我浏览了这些模块并找到了win32,并且根据帮助命令win32gui是其中的一部分它的软件包,所以我尝试了win32.win32gui,它说没有这样的属性

I'm new to coding, I'm not entirely sure what I'm doing. 我是编码的新手,我不确定自己在做什么。

看来win32gui在我用来测试它是否有效的shell中无法识别,但是将其添加到实际的python脚本中后,它就可以正常工作。

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

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