rudi Posted October 5, 2023 Posted October 5, 2023 Hello, this is just a draft. When I click the tray icon, I get the menu immediately, but once I click "script paused", everything freezes: The icon chances to the red "X", but doesn't flash constantly, just alters from "X" to "Autoit" every 20 seconds, and the next click on the tray icon can take over two minutes. What do I miss? Note: When I set TrayAutoPause=1, then click the tray icon, the tray icon is flashing "X" <-->"Autoit" as usual fast, as long as the tray menu is open. Once I click anything in the menu, the "flashing" is freezing as well. #NoTrayIcon #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. Opt("TrayMenuMode", 2) ; don not check / uncheck automatically opt("trayautopause",0) Example() Func Example() Local $idTailLogMain= TrayCreateItem("Start tail main log") Local $idTailErrLog= TrayCreateItem("Start tail error log") TrayCreateItem("") ; Create a separator line. Local $idAbout = TrayCreateItem("About") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $idTailLogMain ; do this case $idTailErrLog ; do that case $idAbout MsgBox(64,@ScriptName,"Version: " & FileGetVersion(@ScriptFullPath) & @CRLF & _ "Autoit Version: " & @AutoItVersion,5) EndSwitch WEnd Sleep(100) EndFunc ;==>Example Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Andreik Posted October 5, 2023 Posted October 5, 2023 I'm not really sure if there is a question or just some remarks about tray behaviors. Are you asking if this is the intended behavior?
rudi Posted October 6, 2023 Author Posted October 6, 2023 This is a question on how to code it correctly, so that the tray icon will react normally, when the script is going to pause. When using the default tray icon, then click on it with trayautopause=1, then it behaves as expected. That's why I assume, that I made a mistake when coding my custom tray menu? Earth is flat, pigs can fly, and Nuclear Power is SAFE!
ioa747 Posted October 6, 2023 Posted October 6, 2023 (edited) On 10/5/2023 at 1:28 PM, rudi said: but once I click "script paused", everything freezes this seems to me It's normal. If script pauses everything freezes Unless you put your own pause where you can managed, while the rest of the program runs In addition, I suggest you to put it in on event mode so that it does not get confused with the flow of the rest of the program Here is an example expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <WindowsConstants.au3> #include <TrayConstants.au3> #include <WinAPISys.au3> #include <Misc.au3> #Region ===( Tray_Menu )=== Opt("TrayMenuMode", 1 + 2) ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Global $idExit, $idPaused, $idHelpInfo, $bPaused = True $idHelpInfo = TrayCreateItem("Help info") TrayItemSetOnEvent(-1, "TRAY_ShowHelp") $idPaused = TrayCreateItem("Pause", -1, -1, 1) TrayItemSetOnEvent(-1, "TRAY_TogglePause") TrayItemSetState(-1, $TRAY_UNCHECKED) TrayCreateItem("") ; ---- Create a separator line. $idExit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "TRAY_Exit") TraySetClick(8) ; (8) = Pressing secondary mouse button will display the tray menu. TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TRAY_TogglePause") TraySetIcon("imageres.dll", -119) TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu TraySetToolTip("HotKeySet" & @CRLF & "Click to Pause / UnPause") #EndRegion ===( Tray_Menu )=== ;Active Window Global $g_ActiveWnd[4] ; 0=winHandle, 1=WinTitle, 2=WinStyle, 3=WinExStyle ; Enable hotkeys ;~ HotKeySet("#^t", "_WinTogleOnTop") ; Win+Ctrl+T ;~ HotKeySet("#^g", "_GoogleSearch") ; Win+Ctrl+G TRAY_TogglePause() ;********************************** While Sleep(50) If $bPaused Then ContinueLoop _GetActiveWindow() WEnd ;********************************** ;---------------------------------------------------------------------------------------- Func TRAY_Exit() Exit EndFunc ;==>TRAY_Exit ;---------------------------------------------------------------------------------------- Func TRAY_TogglePause() If $bPaused = False Then $bPaused = True TrayItemSetState($idPaused, $TRAY_CHECKED) ; $TRAY_UNCHECKED, $TRAY_CHECKED TraySetIcon("imageres.dll", -3) ; Disable hotkeys ConsoleWrite("Disable hotkeys" & @CRLF) HotKeySet("#^t") ; Disable Win+Ctrl+T HotKeySet("#^g") ; Disable Win+Ctrl+G Else $bPaused = False TrayItemSetState($idPaused, $TRAY_UNCHECKED) ; $TRAY_UNCHECKED, $TRAY_CHECKED TraySetIcon("imageres.dll", -119) ; Enable hotkeys ConsoleWrite("Enable hotkeys" & @CRLF) HotKeySet("#^t", "_WinTogleOnTop") ; Win+Ctrl+T HotKeySet("#^g", "_GoogleSearch") ; Win+Ctrl+G EndIf EndFunc ;==>TRAY_TogglePause ;---------------------------------------------------------------------------------------- Func TRAY_ShowHelp() Local $sTxt = "" $sTxt &= "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF $sTxt &= "Window Togle On Top Win+Ctrl+T" & @CRLF $sTxt &= "Google secected word Win+Ctrl+G" & @CRLF $sTxt &= "" & @CRLF $sTxt &= " click to exit" & @CRLF $sTxt &= " " ToolTip($sTxt, (@DesktopWidth * 0.75), @DesktopHeight * 0.25, " Help:", 1) While 1 If _IsPressed("01") Then ExitLoop ; 01 Left mouse button Sleep(50) WEnd ToolTip("") EndFunc ;==>TRAY_ShowHelp ;---------------------------------------------------------------------------------------- Func _GetActiveWindow() Local $AnyWindow $AnyWindow = WinGetHandle("[ACTIVE]") If $g_ActiveWnd[0] <> $AnyWindow Then $g_ActiveWnd[0] = $AnyWindow $g_ActiveWnd[1] = WinGetTitle($g_ActiveWnd[0]) ConsoleWrite("$g_ActiveWnd[1]=" & $g_ActiveWnd[1] & @CRLF) $g_ActiveWnd[2] = _WinAPI_GetWindowLong($g_ActiveWnd[0], $GWL_STYLE) ;ConsoleWrite("$g_ActiveWnd[2]=" & $g_ActiveWnd[2] & @CRLF) $g_ActiveWnd[3] = _WinAPI_GetWindowLong($g_ActiveWnd[0], $GWL_EXSTYLE) ;ConsoleWrite("$g_ActiveWnd[3]=" & $g_ActiveWnd[3] & @CRLF) EndIf EndFunc ;==>_GetActiveWindow ;---------------------------------------------------------------------------------------- Func _WinTogleOnTop() Local $iStyle = _WinAPI_GetWindowLong($g_ActiveWnd[0], $GWL_EXSTYLE) Local $iStyleTopMost = BitOR($iStyle, $WS_EX_TOPMOST) If $iStyle = $iStyleTopMost Then WinSetOnTop($g_ActiveWnd[0], "", 0) Else WinSetOnTop($g_ActiveWnd[0], "", 1) EndIf EndFunc ;==>_WinTogleOnTop ;---------------------------------------------------------------------------------------- Func _SendEx($ss, $warn = "") ;Send the string $ss after the Shift Alt and Ctrl keys are released. ;Optionally give a warning after 1 sec if any of those keys are still down. ;Requires misc.au3 to be included in the script for the _IsPressed function. Local $iT = TimerInit() While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") If $warn <> "" And TimerDiff($iT) > 1000 Then MsgBox($MB_TOPMOST, "Warning", $warn) EndIf Sleep(50) WEnd Send($ss) EndFunc ;==>_SendEx ;---------------------------------------------------------------------------------------- Func _GoogleSearch() ;ConsoleWrite("- GoogleSearch" & @CRLF) Local $ClipBack = ClipGet() ; backup clip data ClipPut("<Empty>") ; <Empty> _SendEx("^c") Local $sWord = ClipGet() Sleep(20) If $sWord = "<Empty>" Then ConsoleWrite("Clipboard: " & $sWord & @CRLF) Else ShellExecute("https://www.google.gr/search?q=" & $sWord & "") EndIf ClipPut($ClipBack) ; Restore clip data EndFunc ;==>_GoogleSearch ;---------------------------------------------------------------------------------------- Edited October 6, 2023 by ioa747 Correction I know that I know nothing
rudi Posted October 9, 2023 Author Posted October 9, 2023 @ioa747 thanks for your suggestions, I'll try them tomorrow. I'm not really 100% sure, but I think, that the "TrayPause" did work fine before, propably AI v3.3.14 Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now