右击托盘图标 Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: arcticir, tmplinshi

zcw1030
Posts: 27
Joined: 03 Mar 2020, 04:09

右击托盘图标

Post by zcw1030 » 10 Jun 2020, 03:52

大家好,不知能否用ahk实现右击托盘图标的动作,就是鼠标右击截图中的图标,谢谢。
Attachments
Snipaste_2020-06-10_13-10-06.png
Snipaste_2020-06-10_13-10-06.png (30.81 KiB) Viewed 25629 times


zcw1030
Posts: 27
Joined: 03 Mar 2020, 04:09

Re: 右击托盘图标

Post by zcw1030 » 10 Jun 2020, 05:28

BoBo wrote:
10 Jun 2020, 04:03
https gist.github.com /tmplinshi/83c52a9dffe65c105803d026ca1a07da Broken Link for safety
HTH
您好,这样改了一下,但是会报错,不知哪里有误。

Code: Select all

; 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.
; ..............: nIdx     - Index of tray icon to click if more than one match.
; ----------------------------------------------------------------------------------------------------------------------
TrayIcon_Button(Shadowsocks, sButton:="R", bDouble:=False, nIdx:=1)
{
    d := 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 := "R"
    oIcons  := TrayIcon_GetInfo(Shadowsocks)
    If ( bDouble )
        PostMessage, oIcons[nIdx].msgid, oIcons[nIdx].uid, %sButton%DBLCLK,, % "ahk_id " oIcons[nIdx].hwnd
    Else
    {
        PostMessage, oIcons[nIdx].msgid, oIcons[nIdx].uid, %sButton%DOWN,, % "ahk_id " oIcons[nIdx].hwnd
        PostMessage, oIcons[nIdx].msgid, oIcons[nIdx].uid, %sButton%UP,, % "ahk_id " oIcons[nIdx].hwnd
    }
    DetectHiddenWindows, %d%
    Return

BoBo
Posts: 3761
Joined: 13 May 2014, 17:15

Re: 右击托盘图标

Post by BoBo » 10 Jun 2020, 05:34

As @tmplinshi (the author of these functions) is a moderator of this forum section (and therefore should speak your native language), I'd guess he'll be able to give you some advice on this. Good luck :thumbup:

zcw1030
Posts: 27
Joined: 03 Mar 2020, 04:09

Re: 右击托盘图标

Post by zcw1030 » 10 Jun 2020, 05:38

BoBo wrote:
10 Jun 2020, 05:34
As @tmplinshi (the author of these functions) is a moderator of this forum section (and therefore should speak your native language), I'd guess he'll be able to give you some advice on this. Good luck :thumbup:
thanks

tmplinshi
Posts: 1599
Joined: 01 Oct 2013, 14:57

Re: 右击托盘图标

Post by tmplinshi » 10 Jun 2020, 07:44

你好,

你需要调用 TrayIcon_Button 这个函数, 而不是去修改它.

Code: Select all

#Include TrayIcon.ahk ; 或者完整路径 D:\Desktop\TrayIcon.ahk

TrayIcon_Button("Shadowsocks.exe", "R")
点击弹出的右键菜单可参考这个脚本:
https://github.com/tmplinshi/RegSsHotkey/blob/master/Lib/RegisterShadowsocksHotkey.ahk

zcw1030
Posts: 27
Joined: 03 Mar 2020, 04:09

Re: 右击托盘图标

Post by zcw1030 » 10 Jun 2020, 08:22

tmplinshi wrote:
10 Jun 2020, 07:44
你好,

你需要调用 TrayIcon_Button 这个函数, 而不是去修改它.

Code: Select all

#Include TrayIcon.ahk ; 或者完整路径 D:\Desktop\TrayIcon.ahk

TrayIcon_Button("Shadowsocks.exe", "R")
点击弹出的右键菜单可参考这个脚本:
https://github.com/tmplinshi/RegSsHotkey/blob/master/Lib/RegisterShadowsocksHotkey.ahk
谢谢!

Post Reply

Return to “请求帮助”