How to make autohotkey work in “OneNote for Window

2019-05-31 01:11发布

问题:

I am trying to add a program specific shortcut, i.e. a shortcut to be used inside OneNote App only, and not the short cut for the opening of app itself. Here is how the present script is:

#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

But the above one works in OneNote desktop and not for the "OneNote for Windows 10" app (OW10A); how do I make it work for that store app? I am not able to find .exe for the store app to mention it in the above script.

回答1:

You can use the #If- or the #IfWinActive- directive to create context-sensitive hotkeys and hotstrings:

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

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

https://autohotkey.com/docs/commands/_If.htm

Use Window Spy to get detailled information about the program windows.

#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