我如何找到在 AutoHotKey 中打开的某个程序的 windows 的数量?

How do I find the number of windows of a certain program that are open in AutoHotKey?

我是AHK的新手,想找出某个程序在任何时候打开的windows个数,并存储在一个变量中。

我有一个脚本可以在我按下大写锁定键时打开 Opera window,但我只想一次打开其中三个 windows,所以当有更多比三个 Opera windows 打开并按下大写锁定键它什么也没做。

我还希望大写锁定按钮永远不会将文本大写(换句话说,始终关闭大写锁定状态)

我该怎么做?

您可以使用 WinGetCount 操作(参见 docs)来获取匹配特定过滤器的 windows 的数量。

您当然需要找到合适的过滤器。您可以使用 AutoHotkey 附带的 Window Spy 实用程序。

在这种情况下我已经做到了:你会看到 Opera windows 的 window class (ahk_class) 是 Chrome_WidgetWin_1 .但是,对于 Chrome、Chromium 等也是如此,因此我们还必须过滤 opera.exe 的程序 EXE 文件名(ahk_exe)。 (我们不 只是 ahk_exe 过滤的原因是我们不想包含诸如 "there are updates available" 框或任何其他非主要 window Opera 可能已经打开了,我猜。)

最后的结果是:

WinGet cnt, Count, ahk_exe opera.exe ahk_class Chrome_WidgetWin_1
MsgBox There are %cnt% Opera windows open