Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python3的活动窗口更改时触发_Python_Python 3.x_Events_Eventtrigger - Fatal编程技术网

python3的活动窗口更改时触发

python3的活动窗口更改时触发,python,python-3.x,events,eventtrigger,Python,Python 3.x,Events,Eventtrigger,我想把这个结果作为某种“自动触发器”(对不起,我是新来的),而不是每隔X秒左右监控一次 到目前为止,我只能像下面的代码那样得到它,但是,除了“滞后”之外,我还需要一直检查它,这听起来不是很有效 我看到了两个类似的答案,但只针对c 谢谢! 佩德罗 from win32gui import GetWindowText, GetForegroundWindow import time last_window = GetWindowText(GetForegroundWindow()) while

我想把这个结果作为某种“自动触发器”(对不起,我是新来的),而不是每隔X秒左右监控一次

到目前为止,我只能像下面的代码那样得到它,但是,除了“滞后”之外,我还需要一直检查它,这听起来不是很有效

我看到了两个类似的答案,但只针对c

谢谢! 佩德罗

from win32gui import GetWindowText, GetForegroundWindow
import time

last_window = GetWindowText(GetForegroundWindow())


while True:
    if a != GetWindowText(GetForegroundWindow()):
        """do whatever i want"""
        a = GetWindowText(GetForegroundWindow())
    time.sleep(1)