增加一种窗口规格到窗口组, 必要时创建组.
GroupAdd, GroupName [, WinTitle, WinText, Label, ExcludeTitle, ExcludeText]
GroupName | 用来保存这种窗口规格的组名. 若组不存在, 则它将被创建. 组名是大小写不敏感的. |
WinTitle | 目标窗口(可能多个)的标题或标题中的部分文字. 此参数可以为空. 注意: 尽管 SetTitleMatchMode 和 DetectHiddenWindows 命令不会直接影响此命令的行为, 他们确实会影响其他组命令的行为诸如 GroupActivate 和 GroupClose. 他们还会影响任何其他命令的 WinTitle 参数中 ahk_group 的使用. 要用窗口的类名进行匹配, 请指定 ahk_class ExactClassName (Window Spy 中可以显示类名).要用窗口的 进程标识符 (PID) 进行匹配, 请指定 ahk_pid %PID变量%. 要使用窗口的 唯一 ID 进行匹配, 请指定 ahk_id %VarContainingID%.要使用窗口组进行匹配, 请指定 ahk_group GroupName (例如组可以包含其他的组). 要减小检测范围, 请指定 多重条件.例如: My File.txt ahk_class Notepad |
WinText | 如果使用这个参数, 则它应该是目标窗口中某个文本元素的子字符串 (在 Window Spy 中会显示窗口中的文本元素).在使用 GroupActivate, GroupDeactivate, 和 GroupClose 命令时, 隐藏文本只有当 DetectHiddenText 设置为 ON 的时候才能检测到. |
Label | 当使用 GroupActivate 命令时, 如果没有找到匹配这种规格的窗口时运行的子程序的标签. 跳到此标签就像使用 Gosub 命令一样. 如果没有, 则省略或留空. |
ExcludeTitle | 标题中包含该参数指定的文字的窗口将被排除. |
ExcludeText | 文本元素中包含该参数指定的文字的窗口将被排除. |
每使用此命令则添加一个新规则到一个组中. 换句话说, 一个组由窗口规格的集合所组成而不是固定的窗口列表. 后面当类似 GroupActivate 的命令使用组时, 会使用这些规则中的每一个检查桌面上的每个窗口. 如果一个窗口匹配组中规则的其中一个, 它被看作一个匹配.
窗口组的典型用法是将相关窗口收集绑定在一起, 这对于包含许多相关窗口的任务或者有许多子窗口的程序是有用的. 例如, 如果您频繁的工作于一个图形程序或文本编辑器的多个实例时, 您可以在一个热键中使用 GroupActivate 命令来切换此程序的每一个实例, 每次一个, 不需要通过 alt-tab 热键或任务栏按钮来找到他们.
由于每组中条目仅需要被添加一次, 此命令通常使用在自动执行段中 (脚本的顶部). 试图添加重复的条目到组中会被忽略.
要在一个组中包含 所有 窗口 (除了特殊的 Program Manager 窗口), 使用这个示例:
GroupAdd, AllWindows
通过在 WinTitle 参数中指定 ahk_group MyGroupName, 所有的窗口命令都可以操作窗口组. WinMinimize, WinMaximize, WinRestore, WinHide, WinShow, WinClose, 和 WinKill 将对一个组中的 所有 窗口起作用. 要仅对顶层的窗口起作用, 参照这个例子:
WinHide % "ahk_id " . WinExist("ahk_group MyGroup")
相反的, 其他的窗口命令例如 WinActivate 和 IfWinExist 将仅对组中的顶层窗口起作用.
GroupActivate, GroupDeactivate, GroupClose
; In the autoexecute section at the top of the script: GroupAdd, MSIE, ahk_class IEFrame ; Add only Internet Explorer windows to this group. return ; End of autoexecute section. ; Assign a hotkey to activate this group, which traverses ; through all open MSIE windows, one at a time (i.e. each ; press of the hotkey). Numpad1::GroupActivate, MSIE, r ; Here's a more complex group for MS Outlook 2002. ; In the autoexecute section at the top of the script: SetTitleMatchMode, 2 GroupAdd, mail, Message - Microsoft Word ; This is for mails currently being composed GroupAdd, mail, - Message ( ; This is for already opened items ; Need extra text to avoid activation of a phantom window: GroupAdd, mail, Advanced Find, Sear&ch for the word(s) GroupAdd, mail, , Recurrence: GroupAdd, mail, Reminder GroupAdd, mail, - Microsoft Outlook return ; End of autoexecute section. Numpad5::GroupActivate, mail ; Assign a hotkey to visit each Outlook window, one at a time.