【问题标题】:open program from windows Tray从 Windows 托盘打开程序
【发布时间】:2019-12-19 09:22:21
【问题描述】:

我制作了一个脚本,可以简单地打开或激活特定的应用程序。
它工作得很好,但我有一个问题,当应用程序最小化到 Windows 托盘时。 热键激活 Else 语句部分,因此它会创建同一应用程序的另一个实例。

!a::
If WinExist("ahk_exe Orzeszek Timer.exe") 
{
   WinActivate, ahk_exe Orzeszek Timer.exe
}
Else {
   Run, "D:\Portable\PortableApps\Orzeszek Timer\Orzeszek Timer.exe"
}
Return

如果应用出现在系统托盘中,我需要脚本帮助以触发 IF 语句部分

非常感谢提前)

【问题讨论】:

  • 最小化到系统托盘的窗口大多是隐藏窗口。尝试在If WinExist 之前添加DetectHiddenWindows OnWinShowWinActivate 之前。
  • user3419297 感谢您的回复 我根据您的建议修改了代码。有变化。但出现的窗口不是应用程序本身,而是似乎与应用程序本身相关的空窗口i.imgur.com/POJXDJN.png
  • DetectHiddenWindows OnWinShow ahk_exe Orzeszek Timer.exe 必须是单独的行。
  • 如果这是预期的脚本 i.imgur.com/7GAlDIf.png 与此脚本相关的空 popapp 窗口。还是我在这里做错了什么?

标签: autohotkey


【解决方案1】:

试试这个

!a::
Process, Exist, Orzeszek Timer.exe
If (Errorlevel != 0) ; is running
{
    WinGet, WinState, MinMax, ahk_exe Orzeszek Timer.exe
    If (WinState = "") ; is minimized to tray
        SendInput, #bo{Enter} ; Win+b activates the tray, o marks the icon of Orzeszek Timer
    else
        WinActivate, ahk_exe Orzeszek Timer.exe
}
else  ; is NOT running
    Run, "D:\Portable\PortableApps\Orzeszek Timer\Orzeszek Timer.exe"
return

如果程序有自己的热键来恢复窗口,请使用该热键而不是#bo{Enter}。

编辑:

如果SendInput, #bo{Enter}太快无法恢复程序,在发送的按键之间加一个sleep:

...
    If (WinState = "") ; is minimized to tray
    {           
        SendInput, #b ; Win+b activates the tray
        ; WinWaitActive, ahk_class Shell_TrayWnd
        Sleep, 300
        SendInput, o ; o marks the icon of Orzeszek Timer. Try first of all manually which letter marks the icon
        Sleep, 300
        SendInput, {Enter}
    }
...

编辑 2:

我下载了那个小型便携式应用程序,这在我的系统上运行:

!a::
Process, Exist, Orzeszek Timer.exe
If (Errorlevel != 0)    ; is running
{
    WinGet, WinState, MinMax, ahk_exe Orzeszek Timer.exe
    If (WinState = "") ; is minimized to tray
        ; SendInput, #bot{Enter}  ; OR: 
        SendInput, #b{Enter}{Up}ot{Enter}
}
else    ; is NOT running
    Run, "D:\Portable\PortableApps\Orzeszek Timer\Orzeszek Timer.exe"
WinWait,  Orzeszek Timer,, 10
If (!ErrorLevel)
{
    WinActivate, Orzeszek Timer
    WinWaitActive Orzeszek Timer,, 5
    If (!ErrorLevel)
        MouseMove, 150, 80, 0
}
return

编辑 3:

如果您在设置中没有启用“始终在通知区域中显示所有图标”选项,请尝试替换

SendInput, #bot{Enter}

SendInput, #b{Enter}{Up}ot{Enter}

【讨论】:

    【解决方案2】:

    user3419297 非常感谢您的脚本,它运行良好。为了打开应用,我稍微修改了一下。

    !a::
    Process, Exist, Orzeszek Timer.exe
    If (Errorlevel != 0) ; is running
    {
        WinGet, WinState, MinMax, ahk_exe Orzeszek Timer.exe
        If (WinState = "") { 
          SendInput, #bo{Right}{Enter}
          Sleep, 500
          CoordMode, Mouse, Window
          MouseMove, 150, 80, 0
        }
        else
            WinActivate, ahk_exe Orzeszek Timer.exe
    }
    else  ; is NOT running
        Run, "D:\Portable\PortableApps\Orzeszek Timer\Orzeszek Timer.exe"
    return
    

    脚本依赖于应用程序只有一个小缺点放在第一位
    在 Windows 托盘列表中。
    当然,我总是可以重新定义 {Right x} 展示位置,但是有没有更有效的方法可以在托盘中自动找到应用展示位置?

    【讨论】:

    • 为什么在#bo 之后{Right}?如果没有其他图标的名称以 o 开头,o 应该在托盘上标记 Orzeszek Timer 的图标。首先手动尝试标记图标的字母(按 Win+b,然后按 o。如果未标记图标,请尝试其他字母,直到图标被标记)。如果SendInput, #bo{Enter} 太快无法恢复程序,请参阅我编辑的答案。
    • 按 Win+b 后,Windows 托盘向上箭头会按原样突出显示,但不幸的是按 a-z 中的任何键都不会导致我的情况。
    • 请参阅我的回答中的 EDIT 3。
    【解决方案3】:

    终于成功了!脚本中唯一缺少的部分是编辑 3 中指出的 {Up} 键,以便系统托盘变得可搜索。所以现在我可以毫无问题地找到确切的密钥。在我的情况下是

                SendInput, #b{Enter}{Up}tt
                Sleep, 100
                SendInput, {Enter}
    

    我真的不知道该怎么感谢你。你帮了我很多)

    【讨论】:

      猜你喜欢
      • 2015-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      相关资源
      最近更新 更多