当系统托盘发生一个特殊事件就执行一个用户自定义函数.
TraySetOnEvent ( 特殊事件标识, "函数" )
特殊事件标识 | 查看下面的 特殊事件标识列表. |
函数 | 要调用的用户自定义函数的名称. |
成功: | 返回 1. |
失败: | 返回 0. |
@error: | 设置为 1 ,如果"函数"未定义. |
特殊事件标识 | 值 | 说明 |
---|---|---|
$TRAY_EVENT_SHOWICON | -3 | 托盘图标将会显示. |
$TRAY_EVENT_HIDEICON | -4 | 托盘图标将会隐藏. |
$TRAY_EVENT_FLASHICON | -5 | 用户定义托盘图标闪烁启用. |
$TRAY_EVENT_NOFLASHICON | -6 | 用户定义托盘图标停止闪烁. |
$TRAY_EVENT_PRIMARYDOWN | -7 | 鼠标主要按键(通常左键)在托盘图标上按下. |
$TRAY_EVENT_PRIMARYUP | -8 | 鼠标主要按键(通常左键)在托盘图标上释放(松开). |
$TRAY_EVENT_SECONDARYDOWN | -9 | 鼠标次要按键(通常右键)在托盘图标上按下. |
$TRAY_EVENT_SECONDARYUP | -10 | 鼠标次要按键(通常右键)在托盘图标上释放(松开). |
$TRAY_EVENT_MOUSEOVER | -11 | 鼠标指针越过托盘图标. |
$TRAY_EVENT_PRIMARYDOUBLE | -13 | 鼠标主要按键(通常左键)在托盘图标上双击. |
$TRAY_EVENT_SECONDARYDOUBLE | -14 | 鼠标次要按键(通常右键)在托盘图标上双击. |
#NoTrayIcon
#include <Constants.au3> ; Required for the $TRAY_EVENT_PRIMARYDOUBLE and $TRAY_EVENT_SECONDARYUP constants.
Opt("TrayMenuMode", 3) ; 默认菜单项目 (脚本暂停中/退出)(Script Paused/Exit) 将不会显示,并且所选项目不能被选中(checkbox不会打勾) . 请参考TrayMenuMode选项1和2(3=1+2).
Opt("TrayOnEventMode", 1)
Example()
Func Example()
TrayCreateItem("关于")
TrayCreateItem("") ; Create a separator line.
TrayCreateItem("退出")
TrayItemSetOnEvent(-1, "ExitScript")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent")
TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "TrayEvent")
TraySetState(1) ; Show the tray menu.
While 1
Sleep(100) ; 空闲循环
WEnd
EndFunc ;==>Example
Func TrayEvent()
Switch @TRAY_ID ; Check the last tray item identifier.
Case $TRAY_EVENT_PRIMARYDOUBLE
; Display a message box about the AutoIt version and installation path of the AutoIt executable.
MsgBox(4096, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
"Version: " & @AutoItVersion & @CRLF & _
"Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.
Case $TRAY_EVENT_SECONDARYUP
MsgBox(4096, "", "The secondary mouse button was released on the tray icon.")
EndSwitch
EndFunc ;==>TrayEvent
Func ExitScript()
Exit
EndFunc ;==>ExitScript