Function Reference


TrayGetMsg

Polls the tray to see if any events have occurred.

TrayGetMsg ( )

Return Value

Returns an event.

The "event" returned is the control ID of the control sending the message, or it is a special event (like the mouse clicking on the tray icon). Or if there is no message, the event is 0.

Event IDs
$TRAY_EVENT_NONE (0): No event
Control ID: the ID of the control sending the message
$TRAY_EVENT_PRIMARYDOWN: the primary mouse button was pressed
$TRAY_EVENT_PRIMARYUP: the primary mouse button was released
$TRAY_EVENT_SECONDARYDOWN: the secondary mouse button was pressed
$TRAY_EVENT_SECONDARYUP: the secondary mouse button was released
$TRAY_EVENT_PRIMARYDOUBLE: the primary mouse button was double pressed
$TRAY_EVENT_SECONDARYDOUBLE: the secondary mouse button was double pressed

Constants are defined in TrayConstants.au3

Remarks

This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.

Related

TrayCreateItem, TrayCreateMenu, TrayItemSetOnEvent

Example

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.

Example()

Func Example()
        Local $idAbout = TrayCreateItem("About")
        TrayCreateItem("") ; Create a separator line.

        Local $idExit = TrayCreateItem("Exit")

        TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

        While 1
                Switch TrayGetMsg()
                        Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
                                MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
                                                "Version: " & @AutoItVersion & @CRLF & _
                                                "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path.

                        Case $idExit ; Exit the loop.
                                ExitLoop
                EndSwitch
        WEnd
EndFunc   ;==>Example