Jump to content

Why does input box take so long to display?


Recommended Posts

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:

giphy.gif

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

Link to comment
Share on other sites

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

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

 

I know that I know nothing

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...