WinShow不适用于ahk_class Chrome_WidgetWin_1

时间:2018-03-23 14:21:49

标签: autohotkey

我正在尝试使用以下脚本来显示/隐藏Windows的Slack桌面应用程序:

DetectHiddenWindows, Off
Process, Exist, slack.exe
slackPid = %ErrorLevel%
IfWinNotExist, ahk_pid %slackPid%
{
    WinShow, ahk_pid %slackPid%
}
Else
{
    WinHide, ahk_pid %slackPid%
}

WinHide部分正常运行,但WinShow未显示应用程序,但正确检索了%slackPid

我尝试了WinShowWinActivateWinRestore的每个组合都没有成功。

这个脚本通常有效,但它失败了,类ahk_class Chrome_WidgetWin_1的窗口:我用VS代码和Rocket.Chat +尝试了它们,它们也是构建在Electron上的应用程序,它也失败了。

1 个答案:

答案 0 :(得分:1)

使用进程标识符(PID)可以识别多个窗口。 要找到它,请尝试以下AHK代码:

F1::
list := ""
numberOfwindows := ""
wins := ""
Index := ""
wins2 := ""
Process, Exist, slack.exe
slackPid = %ErrorLevel%
IfWinExist, ahk_pid %slackPid%
    WinHide, ahk_pid %slackPid%
Else
{
    DetectHiddenWindows, On
    WinGet, id, list, ahk_pid %slackPid%
    Loop, %id%
    {
        numberOfwindows := A_Index
        this_ID := id%A_Index%
        WinGetTitle, title, ahk_id %this_ID%
        WinGetClass, class, ahk_id %this_ID%
        wins .= A_Index . ")`ntitle = " title "`n"  "ahk_class ="  " "   class ? A_Index . ")`ntitle = " title "`n" "ahk_class ="  " "  class  "`n`n" : "" 
        If (title = "")
            continue
        WinGet, exStyle, exStyle, ahk_id %this_ID%
        If !(exStyle & 0x100)
            continue
        Index++
        wins2 .= Index . ")`ntitle = " title "`n"  "ahk_class ="  " "   class ? Index . ")`ntitle = " title "`n" "ahk_class ="  " "  class  "`n`n" : "" 
        WinShow, ahk_id %this_ID%
    }
    MsgBox, number of slack windows = %numberOfwindows%`n`n%wins%`n`nnumber of slack windows with title = %Index%`n`n %wins2%
}
return

在代码中将“slack”替换为“chrome”以将其用于Chrome。