如何获取 AutoHotkey 的 ahk_class 名称?
How to get ahk_class name for AutoHotkey?
按照 this link 的说明,下面的代码可以正常工作。
#IfWinActive ahk_class Notepad
a::MsgBox pressed "a"
但是,我只想在 OneNote 上应用热键(windows10,MS office 2016)。
在 TaskManager 的详细信息面板上,onenote 被命名为; ONENOTE.EXE 但以下所有代码均无效。
#IfWinActive ahk_class ONENOTE
a::MsgBox pressed "a"
也不
#IfWinActive ahk_class ONENOTE.EXE
a::MsgBox pressed "a"
如果我犯了一些错误,请告诉我!
如果 window 无法被 Window 间谍检测到,您可以试试这个:
FileDelete, %A_ScriptDir%\Test.txt
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
If !InStr(title, "OneNote")
continue
WinGetClass, class, ahk_id %this_ID%
FileAppend, %title%`tahk_class %class%`n, %A_ScriptDir%\Test.txt
}
If FileExist(A_ScriptDir "\Test.txt")
Run %A_ScriptDir%\Test.txt
编辑:
如果这样找到的标题包含“- OneNote ahk_class ApplicationFrameWindow”(正如我在您的评论中看到的那样),您可以尝试:
SetTitleMatchMode, 2 ; Title can be part of the full title
#If WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote")
a::MsgBox pressed "a" in OneNote
#If ; turn off context sensitivity
按照 this link 的说明,下面的代码可以正常工作。
#IfWinActive ahk_class Notepad
a::MsgBox pressed "a"
但是,我只想在 OneNote 上应用热键(windows10,MS office 2016)。 在 TaskManager 的详细信息面板上,onenote 被命名为; ONENOTE.EXE 但以下所有代码均无效。
#IfWinActive ahk_class ONENOTE
a::MsgBox pressed "a"
也不
#IfWinActive ahk_class ONENOTE.EXE
a::MsgBox pressed "a"
如果我犯了一些错误,请告诉我!
如果 window 无法被 Window 间谍检测到,您可以试试这个:
FileDelete, %A_ScriptDir%\Test.txt
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
If !InStr(title, "OneNote")
continue
WinGetClass, class, ahk_id %this_ID%
FileAppend, %title%`tahk_class %class%`n, %A_ScriptDir%\Test.txt
}
If FileExist(A_ScriptDir "\Test.txt")
Run %A_ScriptDir%\Test.txt
编辑:
如果这样找到的标题包含“- OneNote ahk_class ApplicationFrameWindow”(正如我在您的评论中看到的那样),您可以尝试:
SetTitleMatchMode, 2 ; Title can be part of the full title
#If WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote")
a::MsgBox pressed "a" in OneNote
#If ; turn off context sensitivity