首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用AutoHotKey右键单击Windows 10中的托盘图标

用AutoHotKey右键单击Windows 10中的托盘图标
EN

Stack Overflow用户
提问于 2015-08-06 21:07:35
回答 2查看 3.8K关注 0票数 6

在Windows7中,我有一个AutoHotKey脚本,可以自动正确地单击托盘图标。

代码语言:javascript
运行
复制
#Include %A_Scriptdir%\TrayIcon.ahk
TrayIcon_Button("CCC.exe", "R")

它使用了来自范纳蒂古鲁职位范纳蒂古鲁职位库。

这在Windows 7上运行得很好,但在Windows 10上不再起作用。

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

下面是库中的TrayIcon_Button函数。我没有把整个图书馆都贴出去,因为它很长。

代码语言:javascript
运行
复制
; ----------------------------------------------------------------------------------------------------------------------
; 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
}
EN

Stack Overflow用户

回答已采纳

发布于 2015-09-27 23:55:14

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

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

代码语言:javascript
运行
复制
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

代之以

代码语言:javascript
运行
复制
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

更新:对升级到Windows1607的令人敬畏的用户来说,它又坏了:)

要使它在Windows 10 1607中再次工作,首先遵循最后的规则。在此之后,将其替换为:

代码语言:javascript
运行
复制
SendMessage, 0x418, 0, 0, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_BUTTONCOUNT
SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%key%, ahk_class %sTray%   ; TB_GETBUTTON

使用

代码语言:javascript
运行
复制
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
}

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

票数 6
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31865826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档