Autohotkey 如何使自动热键在“中”工作;OneNote for Windows 10“;应用程序(不是OneNote)?

Autohotkey 如何使自动热键在“中”工作;OneNote for Windows 10“;应用程序(不是OneNote)?,autohotkey,onenote,Autohotkey,Onenote,我正在尝试添加特定于程序的快捷方式,即仅在OneNote应用程序中使用的快捷方式,而不是打开应用程序本身的快捷方式。 以下是当前脚本的内容: #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recom

我正在尝试添加特定于程序的快捷方式,即仅在OneNote应用程序中使用的快捷方式,而不是打开应用程序本身的快捷方式。 以下是当前脚本的内容:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#IfWinActive, ahk_exe OneNote.exe

+Enter::
    Send, {(}!+d{)} 
return
但上述方法适用于OneNote桌面,而不适用于“OneNote for Windows 10”应用程序(OW10A);我如何使其适用于商店应用程序?我无法在上面的脚本中找到商店应用程序的.exe来提及它。

您可以使用#If-或#IfWinActive-指令来创建上下文相关的热键和热字符串:

#If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeWinText")

#IfWinActive, WinTitle ahk_class WinClass, WinText, ExcludeTitle, ExcludeWinText

使用Window Spy获取有关程序窗口的详细信息

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetTitleMatchMode, 2 ; Title can be part of the full title

#If WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote")

    +Enter:: Send, {(}!+d{)}

    ; Here you can add more program specific shortcuts:
    ; ...

; Here you can add specific shortcuts for another program:

#If WinActive("‎- Microsoft Edge ahk_class ApplicationFrameWindow", "Microsoft Edge")

    +Enter:: MsgBox, You pressed Shift+Enter in Microsoft Edge

#If    ; turn off context sensitivity

是否有任何来源可以让我知道如何为其他应用程序做到这一点?我编辑了我的答案,为您提供了更多的解释和链接。