【问题标题】:Right Click on Tray Icon in Windows 10 with AutoHotKey使用 AutoHotKey 右键单击​​ Windows 10 中的托盘图标
【发布时间】:2015-08-06 21:07:35
【问题描述】:

在 Windows 7 中,我有一个 AutoHotKey 脚本,它会自动右键单击托盘图标。

#Include %A_Scriptdir%\TrayIcon.ahk
TrayIcon_Button("CCC.exe", "R")

其中使用了来自FanaticGuru's post 的 TrayIcon.ahk 库。

这在 Windows 7 上运行良好,但在 Windows 10 上不再运行。

有没有办法在 Windows 10 上的 AutoHotKey 脚本中右键单击 TrayIcon?

这是库中的 TrayIcon_Button 函数。我没有发布整个图书馆,因为它相当长。

; ----------------------------------------------------------------------------------------------------------------------
; Function .....: TrayIcon_Button
; Description ..: Simulate mouse button click on a tray icon.
; Parameters ...: sExeName - Executable Process Name of tray icon.
; ..............: sButton  - Mouse button to simulate (L, M, R).
; ..............: bDouble  - True to double click, false to single click.
; ..............: index    - Index of tray icon to click if more than one match.
; ----------------------------------------------------------------------------------------------------------------------
TrayIcon_Button(sExeName, sButton := "L", bDouble := false, index := 1)
{
    Setting_A_DetectHiddenWindows := A_DetectHiddenWindows
    DetectHiddenWindows, On
    WM_MOUSEMOVE      = 0x0200
    WM_LBUTTONDOWN    = 0x0201
    WM_LBUTTONUP      = 0x0202
    WM_LBUTTONDBLCLK = 0x0203
    WM_RBUTTONDOWN    = 0x0204
    WM_RBUTTONUP      = 0x0205
    WM_RBUTTONDBLCLK = 0x0206
    WM_MBUTTONDOWN    = 0x0207
    WM_MBUTTONUP      = 0x0208
    WM_MBUTTONDBLCLK = 0x0209
    sButton := "WM_" sButton "BUTTON"
    oIcons := {}
    oIcons := TrayIcon_GetInfo(sExeName)
    msgID  := oIcons[index].msgID
    uID    := oIcons[index].uID
    hWnd   := oIcons[index].hWnd
    if bDouble
        PostMessage, msgID, uID, %sButton%DBLCLK, , ahk_id %hWnd%
    else
    {
        PostMessage, msgID, uID, %sButton%DOWN, , ahk_id %hWnd%
        PostMessage, msgID, uID, %sButton%UP, , ahk_id %hWnd%
    }
    DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
    return
}

【问题讨论】:

    标签: autohotkey windows-10 system-tray


    【解决方案1】:

    我在 Windows 10 上对其进行了测试。它不适用于隐藏在溢出窗口下的图标,尽管它对可见图标非常有效。

    更新TrayIcon_GetInfo() 中的这三行以获得快速解决方案

    For key, sTray in ["Shell_TrayWnd","NotifyIconOverflowWindow"]
    SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class %sTray%   ; TB_BUTTONCOUNT
    SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%idxTB%, ahk_class %sTray%   ; TB_GETBUTTON
    

    替换为

    For key, sTray in ["NotifyIconOverflowWindow", "Shell_TrayWnd"]
    SendMessage, 0x418, 0, 0, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_BUTTONCOUNT
    SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_GETBUTTON
    

    更新:对于已经升级到 Windows 1607 的优秀用户,它又被打破了:)

    要使其在 Windows 10 1607 中再次运行,请首先遵循最后的规则。之后将这些替换为:

    SendMessage, 0x418, 0, 0, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_BUTTONCOUNT
    SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_GETBUTTON
    

    if ("Shell_TrayWnd" == sTray) {
        SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class %sTray%   ; TB_BUTTONCOUNT
    } else if ("NotifyIconOverflowWindow" == sTray) {
        SendMessage, 0x418, 0, 0, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_BUTTONCOUNT
    }
    if ("Shell_TrayWnd" == sTray) {
        SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%idxTB%, ahk_class %sTray%   ; TB_GETBUTTON
    } else if ("NotifyIconOverflowWindow" == sTray) {
        SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_GETBUTTON
    }
    

    注意:我不认为这些更改是向后兼容的。

    【讨论】:

    • 不再适用于 Windows 10 1709。知道如何解决这个问题吗?也许也来自图书馆的latest version
    • @Otiel 这就是我喜欢 Windows 更新的原因。这个周末我要更新windows。希望我能在周一之前找到解决方案。
    • @Otiel 嘿,我忘了回复。我升级了 Windows,它对我来说仍然可以正常工作。
    • 嗯,这很奇怪。谢谢你让我知道,我会再试一次。您能否分享您正在使用的整个库代码?
    • @JinSnow 这是一个与托盘图标交互的库(顺便说一句,我正在使用您可以在pastebin.com/1iSj6yUn 找到的更新版本)。要模拟单击托盘图标,您需要在 test.ahk 文件中调用 TrayIcon_Button 函数(检查其签名,有几个可用参数 - 左键单击/右键单击...)。
    【解决方案2】:

    在开头添加以下代码,尝试以管理员身份运行 AHK 脚本的官方方法:

    if not A_IsAdmin
    {
       Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
       ExitApp
    }
    

    【讨论】:

    • 我尝试了您的建议,但没有任何区别。问题似乎不在于没有权限的宏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多