MattHiggs Posted September 7 Share Posted September 7 Hello everyone. Consider the following simple script: #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Add_Constants=n #include <TrayConstants.au3> Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 2) $key = "0" $tray1 = TrayCreateItem('Set key') TraySetState($TRAY_ICONSTATE_SHOW) While True ConsoleWrite ( @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & @CRLF ) $msg = TrayGetMsg() Switch ($msg) Case $tray1 If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer $sInputBoxAnswer = InputBox("Input key", "Which character?") If @error = 0 Then $key = $sInputBoxAnswer EndIf EndSwitch Sleep(1000) WEnd This is a simple script that creates a single tray menu item, then creates a loop which displays the time each time the loop iterates and displays an input box to receive the user's input when the tray item is clicked. My question involves the behavior of the script after the tray menu item is clicked. Since the input box function suspends the script until it is closed, I would expect for the script to not continue the iteration of the loop until the input box is displayed and closed by the user, but that is not what I am seeing. Instead, the script continues to iterate the loop many more times until, eventually, the input box is displayed, at which point, the script is paused and waiting for input. See below: I am trying to figure out why the script is behaving this. Where is the delay occurring that would allow multiple iterations of the loop before the expected action is taken? Is it the control sending the message that is has, in fact, been clicked? Is it just taking a while for the input box to display? Anyone with some insight would be appreciated. Link to comment Share on other sites More sharing options...
Danyfirex Posted September 7 Share Posted September 7 Remove the Sleep(1000) Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
pixelsearch Posted September 7 Share Posted September 7 I would suggest to add a timer, because just suppressing Sleep(1000) would display the time in Console hundred of times (each 10ms) instead of each second, maybe something like this : #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Add_Constants=n #include <TrayConstants.au3> Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 2) $key = "0" $tray1 = TrayCreateItem('Set key') TraySetState($TRAY_ICONSTATE_SHOW) Local $hTimer = TimerInit() While True $msg = TrayGetMsg() Switch ($msg) Case $tray1 If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer $sInputBoxAnswer = InputBox("Input key", "Which character?") If @error = 0 Then $key = $sInputBoxAnswer EndIf $hTimer = TimerInit() EndSwitch If TimerDiff($hTimer) > 1000 Then ConsoleWrite ( @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & @CRLF ) $hTimer = TimerInit() EndIf WEnd Link to comment Share on other sites More sharing options...
argumentum Posted September 7 Share Posted September 7 ..I'd use an OnEvent script. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
ioa747 Posted September 15 Share Posted September 15 ticks per second #include <TrayConstants.au3> Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 2) $key = "0" $tray1 = TrayCreateItem('Set key') Local $Tick TraySetState($TRAY_ICONSTATE_SHOW) While True If $Tick <> @SEC Then ConsoleWrite (@HOUR & ":" & @MIN & ":" & @SEC & @CRLF & @CRLF ) $Tick = @SEC EndIf $msg = TrayGetMsg() Switch ($msg) Case $tray1 If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer $sInputBoxAnswer = InputBox("Input key", "Which character?") If @error = 0 Then $key = $sInputBoxAnswer EndIf EndSwitch ;~ Sleep(1000) WEnd pixelsearch 1 I know that I know nothing Link to comment Share on other sites More sharing options...
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