使用 AutoHotKey 在 OneNote 中自动执行操作

Automating actions in OneNote using AutoHotKey

我想为 Microsoft OneNote 中的各种操作分配键盘快捷键。 (令人恼火的是,OneNote 的键盘快捷方式与 Word 和 Excel 不同)。另外 OneNote 不支持宏。所以我正在试用 AutoHotKey。

我想在点击 Ctrl+Alt+Shift+r 时将选定的文本设为红色。我写了简单的脚本文件:

#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 - OneNote$ ; ------ only in windows with title ending with "- OneNote"

^!+r::
Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
return

#IfWinActive ; ------ end of section restricted to specific windows

但是当我按下这些键时它没有做任何事情。当我删除 #IfWinActive 行时,它开始工作。我怎样才能让它只在一个音符内工作?

我认为您可能正在尝试使用正则表达式 title match mode。要使用它,您需要先在脚本顶部指定它,如下所示:

SetTitleMatchMode, RegEx

#IfWinActive, - OneNote$
^!+r::Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
#IfWinActive

还将您的热键压缩成一行,因为它就是这样。
这应该有效(假设它匹配正确的标题,我无法测试它,我不使用 OneNote)


不过,我个人建议与 ahk_exe 匹配。这(可能)在实践中没有什么不同,但在我看来它非常方便。

因此假设可执行文件 运行 OneNote 将被命名为 OneNote.exe(从例如任务管理器或使用例如 WindowSpy* 检查其实际名称)你会这样做(不要使用 Regex title match mode with this):

#IfWinActive, ahk_exe OneNote.exe
^!+r::Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
#IfWinActive

* WindowSpy 一个简洁的小脚本,可以在您的 AHK 安装文件夹中找到