Search code examples
windowautohotkeydetection

AHK WinActive not recognizing window


I'm trying to make a hotkey available to only a sub-window (or toolbox-stlye-window) of Reaper.

Using this "tutorial" on AHK #If and If: https://stackoverflow.com/a/36175810/7863776

I got this far:

#If (WinActive("Plug-in pin connector"))
^Space::
    Click
    MouseMove, 16, 16, 0, R
    Click
    MouseMove, 16, 16, 0, R
Return
#If

When I use the hotkey after clicking into the correct window, the keypress isn't caught by AHK. Doing this with the hotkey outside an If, AHK catches the hotkey but nothing happens. This leads me to believe WinActive isn't seeing the window, while Windowspy clearly does.

These also don't help:

SetTitleMatchMode, 2
DetectHiddenWindows, On

Windowspy shows this

The only sure way to make this hotkey exclusive to that window is with the title "Plug-in pin connector", though neither "ahk_exe reaper.exe", nor "ahk_class #32770" work. I'd be happy if they did. AHK is running as admin.


Solution

  • Based on our discoveries with ACC viewer, please see if this works for you:

    ^Space::
    WinGetText , sWinText , A
    If InStr( sWinText , "Plug-in pin connector" )
        MsgBox , It worked!
    Else
        MsgBox , It didn't work....`n`nHere's what was found: %sWinText%
    Return
    

    Edit: As found by OP in comments below, ControlGetText can be used to detect whether the "Plug-in pin connector" window is active.