请教如何让AutoHotKey的脚本只对某个特定程序有用

2025-03-23 14:09:07
推荐回答(1个)
回答1:

IfWinActive, ahk_class Chrome_WidgetWin_1
{
;语句
}

;如上这样,ahk class可以通过AU_SPY工具获得,或者通过:

1
2

WinGetActiveTitle, title
WinGetClass, outclassid, %title%

获得并输出到变量outclassid。
当然,如果你想等到出现激活的Chrome窗口时继续指令,可以这样写:

1
2
3
4
5
6
7

Loop
{
;循环
IfWinActive, IfWinActive, ahk_class Chrome_WidgetWin_1
Break
}
;退出循环,继续指令

;若果是没发现chrome则打开chrome并打开指定某网页 可以这样写:

1
2
3
4
5
6

IfWinNotExist, ahk_class Chrome_WidgetWin_1
{
run, C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe http://zhidao.baidu.com/
;....
;....
}

;ahk class也可以是窗口标题,可以模糊或者准确匹配【之前加SetTitleMatchMode,1准确/2模糊】。