问题描述
我想为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)
return
#IfWinActive ; ------ end of section restricted to specific windows
但是当我按下这些键时它什么也没做。当我删除#IfWinActive
行时,它开始工作。我如何才能使其仅在一个音符中起作用?
解决方法
我认为您可能正在尝试使用正则表达式title match mode。要使用它,您需要首先在脚本顶部指定它,如下所示:
OneNote.exe
也可以将您的热键压缩到一个内衬中,因为那样就可以了。
那应该可行(假设它匹配正确的标题,我无法测试,我不使用OneNote)
我个人还是建议与ahk_exe
匹配。在实践中,这可能不会有任何区别,但是我认为这非常方便。
因此,假设运行OneNote的可执行文件将命名为#IfWinActive,ahk_exe OneNote.exe
^!+r::Send,!hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255,0)
#IfWinActive
(例如从任务管理器或使用WindowSpy *检查其实际名称),则可以这样做(不要为此使用Regex标题匹配模式) :
{{1}}
* WindowSpy一个精巧的小脚本,它将在您的AHK安装文件夹中找到