在Windows 7中,我有一个AutoHotKey脚本,可以自动右键单击系统托盘图标。
#Include %A_Scriptdir%\TrayIcon.ahk
TrayIcon_Button("CCC.exe", "R")
这段代码使用了来自FanaticGuru的帖子的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
}
test.ahk
文件中调用TrayIcon_Button
函数(请检查其签名,有几个参数可用 - 左键单击 / 右键单击...)。 - OtielTrayIcon_Button("dimmer.exe","R",false, 1)
确实可以运行您的最后一段代码,即使它使用了错误的索引号也能找到它!(在末尾添加msgbox无法解决问题,因为菜单会非常快地打开和关闭) - JinSnow