Jump to content

Recommended Posts

Hello everyone! I'm new to the AutoIT Forum, but have been using AutoIT for a few years now.
I've finally gotten around to TrayTips, which I love the idea they're like Windows Notifications (at least on Win10) see attached photo, it didn't let me insert it as a link from Imgur for some reason...

But, I've been attempting to get the TrayTip to have an onClick action.
I've inserted a Global variable in front of it, and called it within the TrayGetMsg() switch and within the GUIGetMsg() switch, but still nothing happens.

I've managed to make sure the TrayMenu items (not in code snippet) work within the TrayGetMsg() Switch, which I thought that might help with making the TrayTip work. But, after hours of looking into forum posts, I haven't been able to find anything useful and some of the code doesn't work, or it's more complicated than it possibly should be.

traytip.png.ddfb296e3c2a91e696be446488464ac2.png

Here's a code snippet:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
Opt("TrayMenuMode", 1)
Global $GUI = GUICreate("GUI TITLE", 431, 213, -1, -1)
Global $trayTip = TrayTip("AUTOIT Notification", "This is line 1" & @CRLF & "This is line 2", 10)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $trayTip
            MsgBox(0, "Notification Clicked!", " You've Clicked on the Notification!", 5)

    EndSwitch
    Switch TrayGetMsg()
        Case $trayTip
            MsgBox(0, "Notification Clicked!", " You've Clicked on the Notification!", 5)
    EndSwitch
WEnd

 

Is there something I'm missing? or is TrayTip's really not clickable / don't allow actions to be performed from a click?

Also, if this is in the wrong category, please move it to the correct one. I wasn't sure where I should post it.

Link to post
Share on other sites

it shouldn't work like that

;~         Case $trayTip
;~             MsgBox(0, "Notification Clicked!", " You've Clicked on the Notification!", 5)
        Case Else
            ConsoleWrite("$nMsg=" & $nMsg & @CRLF)

it doesn't give me any value

 

As far for Switch TrayGetMsg() is for the tray icon, take a look

#include <StringConstants.au3>
#include <TrayConstants.au3>

Opt("TrayMenuMode", 3) ; These are options 1 and 2 for TrayMenuMode.

Local $bPaused = False
TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")

#Region === Tray_Menu ===
Local $idPaused = TrayCreateItem("Pause", -1, -1, $TRAY_ITEM_RADIO)
TrayItemSetState(-1, $TRAY_UNCHECKED)
TrayCreateItem("") ; Create a separator line.
Local $idExit = TrayCreateItem("Exit")
#EndRegion === Tray_Menu ===

ToolTip(@ScriptName & @CRLF & " ", @DesktopWidth / 2, @DesktopHeight / 5, "Started", 1)
Sleep(3000)
ToolTip("")

While 1
    _GetTrayMsg()
    Sleep(100)
WEnd

Exit

;----------------------------------------------------------------------------------------

Func GoToExit()    ; exit
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func _GetTrayMsg()
    While 1
        Switch TrayGetMsg()

            Case $TRAY_EVENT_PRIMARYDOUBLE ; Paused the loop.
                TogglePause()

            Case $idPaused ; Paused the loop.
                TogglePause()

            Case $idExit ; Exit the loop.
                GoToExit()

        EndSwitch

        If $bPaused = False Then ExitLoop

    WEnd
EndFunc   ;==>_GetTrayMsg
;----------------------------------------------------------------------------------------
Func TogglePause()

    If $bPaused = False Then
        $bPaused = True
        TrayItemSetState($idPaused, $TRAY_CHECKED)    ; $TRAY_UNCHECKED, $TRAY_CHECKED
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
    Else
        $bPaused = False
        TrayItemSetState($idPaused, $TRAY_UNCHECKED)    ; $TRAY_UNCHECKED, $TRAY_CHECKED
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
    EndIf

;~  ConsoleWrite("$bPaused=" & $bPaused & @CRLF)

EndFunc   ;==>TogglePause

;----------------------------------------------------------------------------------------

 

Link to post
Share on other sites

I don't think that there's a way to interact with the tray tip, since looking at the helpfile it doesn't mention anything, and there's nothing returned when you call it: https://www.autoitscript.com/autoit3/docs/functions/TrayTip.htm
This means that setting Global $trayTip = TrayTip('') will do nothing, since nothing is returned from the function (aka like a control ID to do something with when it's clicked). 

I must have notifications/tray tips disabled somewhere since this doesn't do anything on my computer, so I can't test it further. 

 

Here's a thread with some related (not exact issue) information:

The main part of it that should be interesting is from Microsoft (https://learn.microsoft.com/en-us/windows/win32/shell/notification-area?redirectedfrom=MSDN ) : 

Quote

The notification area is not for critical information that must be acted on immediately. It is also not intended for quick program or command access. As of Windows 7, much of that functionality is best accomplished through an application's taskbar button.

 

Edited by mistersquirrle
Add additional info

We ought not to misbehave, but we should look as though we could.

Link to post
Share on other sites

@ioa747 I appreciate the response. It does return "1" as it's value. Which can be found with:

// It returns 1 with "If not @error"
Global $trayTip = TrayTip("AUTOIT Notification", "This is line 1" & @CRLF & "This is line 2", 10)
If not @error Then
    MsgBox(0, "", $trayTip)
EndIf

// using this I was able to replicate the MsgBox using:
// Also Returns True 
if $trayTip = true or 1 then
    MsgBox(0, "", "Notification Shown")
EndIf


@mistersquirrle, Yes, you're not wrong on this.
I can't seem to find the actual Function within AutoITs Program Directory, which maybe locating this can possibly help(?). When searching the directory, finding only: C:\Program Files (x86)\AutoIt3\Examples\Helpfile\TrayTip.au3 example and TrayConstants.au3 is the other only file found that is linked the TrayMenu. But it only contains Global Constants.

I'm thinking the only way to really get this "Click" is now through UDFs, which was something I was trying to avoid.

Link to post
Share on other sites
22 minutes ago, GregoryAM said:

It does return "1" as it's value. Which can be found with:

;// It returns 1 with "If not @error"
Global $trayTip = "TrayTip"  ;TrayTip("AUTOIT Notification", "This is line 1" & @CRLF & "This is line 2", 10)
If not @error Then
    MsgBox(0, "", $trayTip)
EndIf

;// using this I was able to replicate the MsgBox using:
;// Also Returns True
if $trayTip = true or 1 then
    MsgBox(0, "", "Notification Shown")
EndIf

 

Link to post
Share on other sites

@ioa747, adding this into the GUI seems to be calling the Case $trayTip in both the TrayGetMsg() & GUIGetMsg() and showing the MsgBox that's inside of them.

I removed Func _TIP() since it's not doing anything, and replaced the msgbox with the traytip.
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
Opt("TrayMenuMode", 1)
Global $GUI = GUICreate("GUI TITLE", 431, 213, -1, -1)
Global $trayTip = 1
If $trayTip = 1 Then
    Global $trayTip = TrayTip("Notification", "Test Text", 10)
    $trayTip = 0
EndIf
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $trayTip = 0
            MsgBox(0, "Notification Clicked! - GUIGetMsg", " You've Clicked on the Notification!", 2)

    EndSwitch
WEnd

Doing this calls both the TrayTip and shows the MsgBox.

If you remove the 2 seconds from the Msgbox, it's not closable unless you force quit the script.

Link to post
Share on other sites

Well, the Msgbox no longer stays open after the TrayTip is closed and on removing the 2 seconds from MsgBox.

That's a plus, 😅

Now, I'm looking into GUISetOnEvent, or _IsPressed as an option for the TrayTip.
Since there could be potential there.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ioa747
      TrayTipGUI.au3  is a  custom GUI to send a message to the tray from other script
      ... and can accept multiple messages which remain on the screen without the script waiting for the shown time
      can also use any icon  from an external file or internally from registered libraries
       
      TrayTipGUI.au3
      ;https://www.autoitscript.com/forum/topic/209408-traytipgui-to-send-a-message-to-the-tray/ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;TrayTipGUI.au3 ; custom GUI to send a message to the tray #NoTrayIcon #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <WinAPIProc.au3> #include <WinAPISys.au3> Local $MinY Local $iParams = $CmdLine[0] If Not $iParams Then ; examle if no parameters Local $iParams[5] = [4, " * This is an example...", _ "This means that you have run the " & @CRLF _ & " --> " & @ScriptName & " <-- " & @CRLF & @CRLF _ & " without command line parameters." & @CRLF _ & " and for this reason act as demo.", 10, 2061] Else $iParams = $CmdLine EndIf TrayTipGUI($iParams[1], $iParams[2], $iParams[3], $iParams[4]) Exit Func TrayTipGUI($Title, $Msg, $Timeout = 5, $Icon = 0) ;Colors for the TrayMsg GUI. 0x14171b; 0xFFFFFF; 0xBBBBBB; Local $BackColor = 0x14171b, $TitleColor = 0xFFFFFF, $MsgColor = 0xBBBBBB ;Get DeskTop size Local $DTs = WinGetPos("[CLASS:Shell_TrayWnd]") ConsoleWrite("X=" & $DTs[0] & " Y=" & $DTs[1] & " W=" & $DTs[2] & " H=" & $DTs[3] & @CRLF) ; X=0 Y=1040 W=1920 H=40 * <--- main value $MinY = $DTs[1] ;get the cnt of @TrayTipGUI Local $WinCnt = GetTrayCnt() + 1 ConsoleWrite("$WinCnt=" & $WinCnt & @CRLF) ;GUI ;~ Local $hGUI = GUICreate("@TrayTipGUI", 450, 150, @DesktopWidth - 460, @DesktopHeight, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) Local $hGUI = GUICreate("@TrayTipGUI", 450, 150, $DTs[2] - 460, $DTs[1] + $DTs[3], $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor($BackColor) WinSetTrans($hGUI, "", 245) ; * <-- transparency seting range 0 - 255 ;Exit button Local $idExit = GUICtrlCreateButton("X", 427, 3, 20, 20) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetBkColor(-1, $BackColor) GUICtrlSetColor(-1, $TitleColor) ;Title GUICtrlCreateLabel($Title, 10, 10, 410, 35) GUICtrlSetFont(-1, 11, 600, 0, "Arial") GUICtrlSetColor(-1, $TitleColor) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;Msg Local $idMsg = GUICtrlCreateLabel($Msg, 80, 50, 360, 95) GUICtrlSetFont(-1, 11, 600, 0, "Arial") GUICtrlSetColor(-1, $MsgColor) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;~ ************ Icons Library ************************** ;~ C:\Windows\System32\imageres.dll $cnt = 334 --> 0000 ;~ C:\Windows\system32\shell32.dll $cnt = 329 --> 1000 ;~ C:\Windows\SysWOW64\wmploc.dll $cnt = 159 --> 2000 ;~ C:\Windows\System32\ddores.dll $cnt = 149 --> 3000 ;~ C:\Windows\System32\mmcndmgr.dll $cnt = 129 --> 4000 ;~ C:\Windows\system32\ieframe.dll $cnt = 103 --> 5000 ;~ C:\Windows\System32\compstui.dll $cnt = 101 --> 6000 ;~ C:\Windows\System32\setupapi.dll $cnt = 62 --> 7000 Switch $Icon Case 1 To 334 ; icon from C:\Windows\System32\imageres.dll $cnt = 334 GUICtrlCreateIcon("imageres.dll", $Icon * -1, 10, 43, 64, 64) Case 1001 To 1329 ; icon from C:\Windows\system32\shell32.dll $cnt = 329 $Icon -= 1000 GUICtrlCreateIcon("shell32.dll", $Icon * -1, 10, 43, 64, 64) Case 2001 To 2159 ; icon from C:\Windows\SysWOW64\wmploc.dll $cnt = 159 $Icon -= 2000 GUICtrlCreateIcon("wmploc.dll", $Icon * -1, 10, 43, 64, 64) Case 3001 To 3149 ; icon from C:\Windows\System32\ddores.dll $cnt = 149 $Icon -= 3000 GUICtrlCreateIcon("shell32.dll", $Icon * -1, 10, 43, 64, 64) Case 4001 To 4129 ; icon from C:\Windows\System32\mmcndmgr.dll $cnt = 129 $Icon -= 4000 GUICtrlCreateIcon("mmcndmgr.dll", $Icon * -1, 10, 43, 64, 64) Case 5001 To 5103 ; icon from C:\Windows\system32\ieframe.dll $cnt = 103 $Icon -= 5000 GUICtrlCreateIcon("ieframe.dll", $Icon * -1, 10, 43, 64, 64) Case 6001 To 6101 ; icon from C:\Windows\System32\compstui.dll $cnt = 101 $Icon -= 6000 GUICtrlCreateIcon("compstui.dll", $Icon * -1, 10, 43, 64, 64) Case 7001 To 7062 ; icon from C:\Windows\System32\setupapi.dll $cnt = 62 $Icon -= 7000 GUICtrlCreateIcon("setupapi.dll", $Icon * -1, 10, 43, 64, 64) Case Else Local $tmp = StringSplit($Icon, ",") If $tmp[0] = 1 Then ; single icon file If $tmp[1] = 0 Then ; if no icon maximize the msg GUICtrlSetPos($idMsg, 10, 48, 440, 97) ; 80, 50, 360, 90 Else ; single icon file GUICtrlCreateIcon($tmp[1], -1, 10, 43, 64, 64) EndIf ElseIf $tmp[0] = 2 Then ; if .dll file with icon index GUICtrlCreateIcon($tmp[1], $tmp[2] * -1, 10, 43, 64, 64) Else ; unknown situation MsgBox(0, "Else unknown situation", $Icon) EndIf EndSwitch GUISetState(@SW_SHOW, $hGUI) ;shows up the GUI Local $WPos = WinGetPos($hGUI) ;[0]=X; [1]=Y; [2]=Width; [3]=Height WinMove($hGUI, "", $WPos[0], $MinY - 150 - 10, $WPos[2], $WPos[3], 5) ; Begin the timer and store the handle Local $hTimer, $fDiff $hTimer = TimerInit() ;******************************************* Do ; Loop until the TimerDiff > $Timeout Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idExit ExitLoop EndSwitch Sleep(100) ;Find the difference in time from the previous call of TimerInit $fDiff = TimerDiff($hTimer) Until $fDiff > $Timeout * 1000 ;******************************************* ;disappear the GUI WinMove($hGUI, "", $WPos[0], @DesktopHeight, $WPos[2], $WPos[3], 5) ;Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>TrayTipGUI ;---------------------------------------------------------------------------------------- Func GetTrayCnt() ;get the cnt of @TrayTipGUI Local $aData = _WinAPI_EnumDesktopWindows(_WinAPI_GetThreadDesktop(_WinAPI_GetCurrentThreadId())) Local $WinTitle, $WCnt, $WinPos For $i = 1 To $aData[0][0] $WinTitle = WinGetTitle($aData[$i][0]) If $WinTitle = "@TrayTipGUI" Then $WinPos = WinGetPos($aData[$i][0]) If $WinPos[1] < $MinY Then $MinY = $WinPos[1] $WCnt += 1 EndIf Next Return $WCnt EndFunc ;==>GetTrayCnt ;----------------------------------------------------------------------------------------  
       Make_icon_katalog  create 9 X *.jpg files with icons from the dll libraries as albums for easy using in TrayTipGUI.au3
      Make_icon_katalog.au3
      ;https://www.autoitscript.com/forum/topic/209408-traytipgui-to-send-a-message-to-the-tray/ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Make_icon_katalog.au3 ; creating icons albums from the dll libraries #include <StaticConstants.au3> #include <ScreenCapture.au3> ;Icons Library Local $Ldll = "C:\Windows\System32\imageres.dll" ;$cnt = 334 --> 0000 $Ldll &= ";C:\Windows\system32\shell32.dll" ;$cnt = 329 --> 1000 $Ldll &= ";C:\Windows\SysWOW64\wmploc.dll" ;$cnt = 159 --> 2000 $Ldll &= ";C:\Windows\System32\ddores.dll" ;$cnt = 149 --> 3000 $Ldll &= ";C:\Windows\System32\mmcndmgr.dll" ;$cnt = 129 --> 4000 $Ldll &= ";C:\Windows\system32\ieframe.dll" ;$cnt = 103 --> 5000 $Ldll &= ";C:\Windows\System32\compstui.dll" ;$cnt = 101 --> 6000 $Ldll &= ";C:\Windows\System32\setupapi.dll" ;$cnt = 62 --> 7000 $Ldll = StringSplit($Ldll, ";") For $x = 1 To $Ldll[0] ConsoleWrite($Ldll[$x] & @CRLF) Example($Ldll[$x], $x) Next ShellExecute(@ScriptDir) Exit Func Example($IconLib, $Libfactor) $Libfactor = ($Libfactor - 1) * 1000 Local $cnt = _WinAPI_ExtractIconEx($IconLib, -1, 0, 0, 0) ConsoleWrite("$cnt = " & $cnt & @CRLF) Local $C, $Col, $R, $Row, $BtnSz = 48 $Col = (@DesktopWidth / 3 * 2) / $BtnSz $Row = Int($cnt / $Col) Local $hGUI = GUICreate($IconLib, $Col * $BtnSz + $BtnSz, $Row * $BtnSz, 0, 0, -1) Local $Icon[$cnt + 1] $Icon[0] = 0 Local $i = 1 For $R = 0 To $Row For $C = 0 To $Col ReDim $Icon[UBound($Icon) + 1] $Icon[$i] = GUICtrlCreateIcon($IconLib, -1 * $i, $C * $BtnSz, $R * $BtnSz, $BtnSz, $BtnSz) GUICtrlCreateLabel($i & " ", $C * $BtnSz, $R * $BtnSz, $BtnSz / 2, 12, $SS_RIGHT) ;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetTip($Icon[$i], "index " & $i) $i += 1 Next Next GUISetState(@SW_SHOW) WinWaitActive($hGUI, "", 5) If $Libfactor = 0 Then $Libfactor = "0000" Local $WPos = WinGetPos($hGUI) ; [0]=X [1]=Y [2]=Width [3]=Height ; Capture region _ScreenCapture_Capture(@ScriptDir & "\" & $Libfactor & ".jpg", $WPos[0], $WPos[1], $WPos[2], $WPos[3]) GUIDelete($hGUI) EndFunc ;==>Example
      Example for using TrayTipGUI
      Example.au3
      #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Example.au3 ; Example for using TrayTipGUI Local $Str = "This is an Example for using " & @CRLF _ & "--> TrayTipGUI.au3" & @CRLF _ & "and come in screen like notification" Tip("This is an example...", $Str, 6, 2060) Sleep(4000) $Str = "and can accept multiple messages " & @CRLF _ & "which remain on the screen" & @CRLF _ & "without the script waiting" & @CRLF _ & "for the shown time " Tip("This is another one example...", $Str, 7, '"shell32.dll", 236') ; with icon file Sleep(5000) $Str = "can also use any icon" & @CRLF _ & " from an external file" & @CRLF _ & "or internally from registered libraries" Tip("This is one more example...", $Str, 8, 1236) ; internal with 1236 Sleep(4000) Tip("This is the title ...", _ "... and this is the body " _ & " of the mesage " _ & " with multiline concatenation example", _ 8, 228) Sleep(5000) Tip("This is an Example without icon for maximize the mesage area", _ "AutoIt v3 is a freeware BASIC-like scripting language " _ & "designed for automating the Windows GUI and general scripting. " _ & "It uses a combination of simulated keystrokes, " _ & "mouse movement and window control manipulation " _ & "in order to automate tasks in a way not possible " _ & "or reliable with other languages e.g. VBScript and SendKeys ", _ 15, 0) ;---------------------------------------------------------------------------------------- Func Tip($Title, $Msg, $Timeout = 5, $Icon = 2060) Local $FilePath = @ScriptDir & "\TrayTipGUI.au3" Local $Param = '"' & $Title & '" "' & $Msg & '" "' & $Timeout & '" "' & $Icon & '"' Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName($FilePath) & " " & $Param) EndFunc ;==>Tip ;----------------------------------------------------------------------------------------  
       
      Please, leave your comments and experiences here.  
    • By Iraj
      Hi Team,
      Greetings!
      I need to embed traytip in some autoit code where I dont need highlighted unwanted content & also can I have a custom logo instead of the presets.
      Thanks!
       
      #include <TrayConstants.au3> TrayTip("TrayTip Title", "TrayTip Content", 2, $TIP_ICONASTERISK)  

    • By Blueman
      Hey all,

      I have a question about the Windows-10 Traytips and how to assign a function on them.
      So the Traytip will be displayed and when i click it i would like to run a function.
       
      Currently i am looking at the following Topic; https://www.autoitscript.com/forum/topic/140699-tray-notifications-redirector/

      Tried it and it works fine, but now all my TrayTIps are clickable to the same function.
      Is it possible to read the Traytip name and then run a function according to what tip is showing?
       
      Thanks  
    • By dwaynek
      traytip isn't working in windows 10. nothing happens when i use the Traytip command.
      here's a simple script i used:
      TrayTip("I'm a title", "I'm the message", 5) i tried changing the registry setting HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced ( which didn't have EnableBalloonTips) and creating a DWORD entry called EnableBalloonTips and setting it to 1 and logging off then back in. that did not resolve the problem.
      i'm running Windows 10 v1709 b16299.431
    • By Zinthose
      Hey all!

      It's been a while since I've posted but here is a simple little function I thought I'd share that allows you to keep a script process active for a minimum amount of time.

      I use this to ensure the process is active to ensure any TrayTips remain visible.  But I'm sure there is far more interesting uses for this.
      How it Works
      The coder calls the KeepAlive function with the number of seconds he/she wants to ensure the process will remain active for the next n seconds.  Let's say you just called the TrayTip function with 15 seconds display time.  You might call KeepAlive with 18 seconds to ensure the process stays active for the next 18 seconds.  If the process is closed after that, then the process will close normally.
      #Region - KeepAlive Functions ;## Function used to ensure the process stays active for the next n seconds. This is useful to ensure ToolTips ect remain visible. #cs - Example TrayTip(@ScriptName, "This Tip will be called just prior to exit of process.", 5) KeepAlive(8) Exit #ce - Example Func KeepAlive($Seconds = 5) Global $KeeyAlive_IsActive = False Global $KeeyAlive_Init = 0 Global $KeeyAlive_Timeout = 0 ;## Check if there is a previously set timer and only set the new value if it is more than the previously set value. If $KeeyAlive_Timeout - TimerDiff($KeeyAlive_Init) < $Seconds * 1000 Then $KeeyAlive_Init = TimerInit() $KeeyAlive_Timeout = $Seconds * 1000 EndIf ;## If the callback is not yet regerister to execute on exit, register it now. If Not $KeeyAlive_IsActive Then $KeeyAlive_IsActive = True OnAutoItExitRegister("__KeepAlive_OnExit") EndIf EndFunc ;## Private On Exit Function used to ensure program remains active for a previously defined number of seconds. Func __KeepAlive_OnExit() ;## If closeing due to Loffoff or shutdown. Allow it without Delay. If @exitMethod > 2 Then Return ;## Check for reasons that process should be clsoed immediatly without delay. If @exitMethod > 2 Or Not IsDeclared("KeeyAlive_IsActive") Or Not IsDeclared("KeeyAlive_Init") Or Not IsDeclared("KeeyAlive_Timeout") Or TimerDiff($KeeyAlive_Init) > $KeeyAlive_Timeout Then Return ;## Pause Process for the time remaining. ConsoleWrite("Keeping Alive for " & Int($KeeyAlive_Timeout - TimerDiff($KeeyAlive_Init)) & "ms" & @CRLF) Sleep($KeeyAlive_Timeout - TimerDiff($KeeyAlive_Init)) EndFunc #EndRegion Enjoy!
×
×
  • Create New...