autohotkey - 使用 AutoHotKey 右键单击​​ Windows 10 中的托盘图标

标签 autohotkey windows-10 system-tray

在 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
}

最佳答案

我在 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
}

注:我认为这些更改中的任何一个都不向后兼容。

关于autohotkey - 使用 AutoHotKey 右键单击​​ Windows 10 中的托盘图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31865826/

相关文章:

if-statement - AHK if 语句忽略条件

autohotkey - 使用 AutoHotkey 控制操纵杆 Axis

docker - Docker Kitematic连接ETIMEDOUT错误

python - 如何处理Python 3.8中Kivy安装错误?

c# - 如何制作仅在系统托盘中运行的 .NET Windows 窗体应用程序?

windows - AutoHotKey 是否可以确定窗口是否具有滚动功能/交互?

arrays - 如何在 Autohotkey 中发送数组变量的值?

windows - 在 Windows 10 中使用 powershell 在多个桌面上启动程序

带有 controlsfx 通知组件的 javafx NullPointerException

c# - 使用 .NET 4 让程序最小化到系统托盘的最简单方法