在Windows 10中使用AutoHotKey右键单击任务栏图标 [英] Right Click on Tray Icon in Windows 10 with AutoHotKey

查看:346
本文介绍了在Windows 10中使用AutoHotKey右键单击任务栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 7中,我有一个AutoHotKey脚本,该脚本会自动右键单击任务栏图标.

In Windows 7, I had an AutoHotKey script that would automatically Right-Click on a tray icon.

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

使用了FanaticGuru的TrayIcon.ahk库发布.

这在Windows 7上运行正常,但在Windows 10上不再运行.

This worked just fine on Windows 7, but no longer works on Windows 10.

是否可以在Windows 10的AutoHotKey脚本中右键单击TrayIcon?

Is there a way to right click on a TrayIcon in an AutoHotKey script on Windows 10?

这是库中的TrayIcon_Button函数.我避免发布整个库,因为它很长.

Here is the TrayIcon_Button function from the library. I refrained from posting the entire library since it is fairly long.

; ----------------------------------------------------------------------------------------------------------------------
; 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上对其进行了测试.它对于隐藏在溢出窗口下的图标不起作用,尽管它对于可见的图标也可以正常工作.

I tested it on Windows 10. It was not working for the icons hidden under overflow window, although it was working perfectly for the visible icons.

TrayIcon_GetInfo()中更新这三行以快速解决

Update these three lines in TrayIcon_GetInfo() for a quick solution

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的出色用户,它再次被破坏了:)

Update: To awesome users who have upgraded to Windows 1607, it is broken again :)

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

To make it work again in Windows 10 1607, first follow those last rules. After that replace these with:

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
}

注意:我认为这些更改均不向后兼容.

Note: I don't think any of these changes are backward compatible.

这篇关于在Windows 10中使用AutoHotKey右键单击任务栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆