该AutoHotkey的初级教程包括示例脚本演示窗口具体的热键和热字串.
#IfWinActive ahk_class Notepad
::msg::You typed msg in Notepad
#IfWinActive
#IfWinActive untitled - Paint
::msg::You typed msg in MSPaint!
#IfWinActive
Run Code Online (Sandbox Code Playgroud)
第二个例子是相当不言自明的:检查一个名为"untitled - Paint"的窗口.这是第一个使用的例子ahk_class让我感到困惑.
我无法在AHK文档中找到对变量的任何解释.根据AHK论坛帖子,ahk_class是Windows Spy给出的窗口名称,帖子没有详细说明.
使用ahk_class Notepad和之间会有什么区别Untitled - Notepad吗?如果替换为第二个例子会有效#IfWinActive ahk_class Paint吗?
什么是ahk_class如何以及如何将其用于窗口匹配?
Ole*_*leg 13
来自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
Run Code Online (Sandbox Code Playgroud)
找到它后,你可以在任何你可以使用窗口标题的地方使用它,而不是写WinActivate, Untitled - Notepad你可以写WinActivate, ahk_class Notepad.