Reputation: 2501
I need something like a msgbox
displaying in my script but without the need for waiting to click okay.
What I need is to display a string for a certain duration of time and then make it disappear. It would be helpful if it can display a live timer string but not mandatory.
Something like:
;//...
msgbox, MyInformationString; display information
sleep, 30000 ; wait 30 seconds
;// close msgbox but HOW ???
;//...
It doesn't have to be the msgbox
command. but I can not figure out how to create a new popup or any other way to display information. Format is the least of my concern here.
Upvotes: 7
Views: 11601
Reputation: 6371
Look at msgbox
in the docs. Since you are producing the msgbox
via AutoHotkey, you can set a time limit on it that will close the message automatically. That means that you don't have to push anything - the box appears and then just goes away.
MsgBox [, Options, Title, Text, Timeout]
Timeout
is the last parameter:
(optional) Timeout in seconds, which can contain a decimal point but is not an expression by default. In v1.1.06+, this can be a forced expression such as % mins*60.
If this value exceeds 2147483 (24.8 days), it will be set to 2147483. After the timeout has elapsed the message box will be automatically closed and the IfMsgBox command will see the value TIMEOUT.
Known limitation: If the MsgBox contains only an OK button, IfMsgBox will think that the OK button was pressed if the MsgBox times out while its own thread is interrupted by another.
Upvotes: 12
Reputation: 86240
If you would really like your own count down, you can create a GUI that acts as your MsgBox.
In this example, we have 4 parameters.
Here's the way your code changes from normal MsgBox, to this one.
MsgBox, Title, Msg
OtherCode
return
to
MsgBoxTimed("Title", "Msg", 10, "Foo")
return
Foo:
OtherCode
return
This function needs to be in the same file, or #Include
d
MsgBoxTimed(title, msg, seconds, complete="") {
static init = false, _seconds, _complete
global Msg92, Seconds92
if (!init)
{
init := true
Gui, 92:Font, s24
Gui, 92:Add, Text, vMsg92 Center w360, %msg%
Gui, 92:Font, s30 cRed
Gui, 92:Add, Text, vSeconds92 Center w360, %seconds%
}
_seconds := seconds
_complete := complete
GuiControl, 92:, Msg92, %msg%
Gui, 92:Show, w400 h150, %title%
Update92:
GuiControl, 92:, Seconds92, %_seconds%
_seconds -= 1
if (_seconds > 0) {
SetTimer, Update92, -1000
}
else {
Gui, 92:Hide
if (_complete)
SetTimer, %_complete%, -1
}
return
}
Upvotes: 10