ahk_class是什么?我怎样才能将它用于窗口匹配?

ahk_class是什么?我怎样才能将它用于窗口匹配?

问题描述:

AutoHotkey Beginner Tutorial包括一个sample script来演示窗口特定的热键和热点。ahk_class是什么?我怎样才能将它用于窗口匹配?

#IfWinActive ahk_class Notepad 
::msg::You typed msg in Notepad 
#IfWinActive 

#IfWinActive untitled - Paint 
::msg::You typed msg in MSPaint! 
#IfWinActive 

第二个例子非常明了:检查名为“untitled - Paint”的窗口。这是第一个使用ahk_class的例子,让我感到困惑。

我还没有找到AHK documentation中的变量的任何解释。 According to an AHK forum post,ahk_class是Windows Spy给出的窗口的名称,该帖子没有详细介绍。

使用ahk_class NotepadUntitled - Notepad会有什么区别吗?如果替换为#IfWinActive ahk_class Paint,第二个示例是否可以工作?

ahk_class什么是ahk_class?我怎样才能将它用于窗口匹配?

+0

附加说明:我正在使用AutoHotkey的便携版本,[它不包含WindowSpy](https://stackoverflow.com/questions/45552452/could-not-launch-file-au3-spy-exe) 。 –

https://autohotkey.com/docs/misc/WinTitle.htm#ahk_class

窗口类是一组属性的系统使用作为模板来创建一个窗口。换句话说,窗口的类名标识了它是什么类型的窗口。

换句话说,你可以用它来识别相同类型的窗口,如果你打开记事本的标题是Untitled - Notepad,如果你把它保存到temp.txt标题将成为temp - Notepad。另一方面ahk_class将永远保持Notepad

如果用#IfWinActive ahk_class MSPaintApp代替它,第二个示例将起作用,因为这是mspaint的类。

通常情况下,您会发现ahk_class使用Window Spy,然后在您的脚本中使用它。如果你没有Window Spy,你可以使用下面的快捷键:

#1::WinGetClass, Clipboard, A ; Will copy the ahk_class of the Active Window to clipboard 

后,你发现了它,你可以用它在任何地方,你可以使用窗口标题,例如,而不是写WinActivate, Untitled - Notepad你可以写WinActivate, ahk_class Notepad

+0

所以'ahk_class'正在寻找程序名称,而不是窗口名称。 –

+1

@StevenVascellaro它不完全是程序名称,一个程序可以有不同类型的窗口,不同的程序有时可以具有相同的ahk_class。现在就把它想成程序名称,然后用它来识别一个程序。 – Oleg

检查this文章。 Ahk_class是在您使用WindowSpy工具时为您提供的类。该工具应与AutoHotkey可执行文件位于同一文件夹中。

+0

我在回答中特别引用了论坛帖子,说这没有帮助。我的AutoHotkey版本[没有WindowsSpy工具](https://stackoverflow.com/questions/45552452/could-not-launch-file-au3-spy-exe)。 –