按照此链接的指示,下面的代码工作得很好。
#IfWinActive ahk_class Notepad
a::MsgBox pressed "a"不过,我只想在OneNote上应用热键(windows 10,MS office 2016)。在TaskManager上的详细面板上,onenote被命名为;ONENOTE.EXE,但是下面的所有代码都不起作用。
#IfWinActive ahk_class ONENOTE
a::MsgBox pressed "a"nor
#IfWinActive ahk_class ONENOTE.EXE
a::MsgBox pressed "a"如果我犯了什么错误,请告诉我!
发布于 2018-08-23 05:26:10
如果窗口间谍无法检测到该窗口,则可以尝试以下操作:
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作为在这个答案中。
https://stackoverflow.com/questions/51978247
复制相似问题