0

by follow a instruction of this link the below code works fine.

#IfWinActive ahk_class Notepad
a::MsgBox pressed "a"

However, I want to apply the hotkey on OneNote only (windows 10, MS office 2016). On the detail panel on TaskManager, the onenote is named ; ONENOTE.EXE but all the below codes are do not work.

#IfWinActive ahk_class ONENOTE
a::MsgBox pressed "a"

nor

#IfWinActive ahk_class ONENOTE.EXE
a::MsgBox pressed "a"

Let me know if I made some mistakes!

Nam
  • 173
  • 2
  • 13
  • 2
    Use the included **Window Spy** utility (accessible from the script's tray menu or the start menu) to get the ahk_class of the window. – user3419297 Aug 23 '18 at 04:45
  • Thanks for let me know how to, however seem like the OneNote 2016 is not detectable as I've tested (a window screen is separated with many parts, not able to select the whole panel.). thanks though, I'll try to find another approach. – Nam Aug 23 '18 at 05:00

1 Answers1

1

If the window is not detectable by Window Spy, you can try this:

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

EDIT:

If the title found this way contains "- OneNote ahk_class ApplicationFrameWindow" (as I see in your comment), you can try:

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

as in this answer.

user3419297
  • 9,537
  • 2
  • 15
  • 24
  • Sorry, I don't understand what is this code for. is this create a test.txt on the same location with this code.ahk placed. and contains `OneNote ahk_class Windows.UI.Core.CoreWindow ?{my textbook tree name} ≫ ?{my document name} ?- OneNote ahk_class ApplicationFrameWindow {my document name} - OneNote ahk_class Framework::CFrame` I don't know what is this for and I don't how to modify to apply on mine, sorry for my ignorance. – Nam Aug 23 '18 at 06:49
  • Thanks for helping me, The code works super well on the plain OneNote, however, on the another OneNote 2016, nothing happening though. even the title contains the letter 'OneNote', currently I'm just stick to turn on the autohotkey when I'm on work with the app. – Nam Aug 23 '18 at 10:00
  • 1
    If you want to send the hotkey to the OneNote 2016 window (if its active), try `SetTitleMatchMode, 2` and `#If WinActive("- OneNote ahk_class Framework::CFrame")` instead. – user3419297 Aug 23 '18 at 10:11
  • :O ?!?! IMPRESSIVE! It works ! thank you so so much, I don't know how did you done that. just thanks for you work!! – Nam Aug 23 '18 at 10:14
  • 1
    To understand how the above code works, see https://autohotkey.com/docs/commands/WinGet.htm#ex2 – user3419297 Aug 23 '18 at 10:18
  • Thanks, I'll note the article to make the code for apply on each apps, thanks again! – Nam Aug 23 '18 at 10:21