当消息的文本包含变量时,如何使用带有计时器的AutoHotkey消息框? [英] How can I use an AutoHotkey message box with a timer when the Text of the message contains variables?

查看:140
本文介绍了当消息的文本包含变量时,如何使用带有计时器的AutoHotkey消息框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试AHK脚本时,我想添加MsgBox语句以帮助我知道已到达一段代码,并且我可能想在消息中包括一些变量.我希望消息框有一个超时时间,以便它在5秒后自动关闭.我想坚持使用消息框,而不是使用ToolTip或依靠脚本中需要包含的功能.

我正在寻找单行代码,因此我可以在不需要时轻松地将其注释掉.

我遇到的问题是将多个变量传递给Text参数的MsgBox,将其与Timeout参数的位置混淆了.还有另一种写变量的方式,这样它们就不会被解释为单独的参数了吗?

WinGetPos, X, Y, W, H, A  ; "A" to get the active window's position.

; The timeout on this example does not work and the 5 is not shown.
MsgBox, 64, Debug, The active window is at %X%, %Y%, %W%, %H%, 5

; The timeout on this example works.  Is there a way to write this on one line?
msg=The active window is at %X%, %Y%, %W%, %H%
MsgBox, 64, Debug, %msg%, 5

解决方案

如果消息文本中包含逗号,则需要使用反引号`符号将其转义.

MsgBox, 64, Debug, The active window is at %X%`, %Y%`, %W%`, %H%, 5

还有一些其他字符也需要转义.. >

When debugging an AHK script I like to add MsgBox statements to help me know that a section of code was reached and I may want to include some variables in the message. I'd like the message box to have a timeout so it self closes after 5 seconds. I'd like to stick with the message box instead of using the ToolTip or relying on a function I would need to include in the script.

I'm looking for a single line of code so I can easily comment it out when it's not needed.

The problem I'm having is passing multiple variables to the MsgBox for the Text parameter is confusing it with the positioning of the Timeout parameter. Is there another way of writing my variables so they are not interpreted as separate parameters?

WinGetPos, X, Y, W, H, A  ; "A" to get the active window's position.

; The timeout on this example does not work and the 5 is not shown.
MsgBox, 64, Debug, The active window is at %X%, %Y%, %W%, %H%, 5

; The timeout on this example works.  Is there a way to write this on one line?
msg=The active window is at %X%, %Y%, %W%, %H%
MsgBox, 64, Debug, %msg%, 5

解决方案

If you have commas in the text of your message you need to escape them with the backtick ` symbol.

MsgBox, 64, Debug, The active window is at %X%`, %Y%`, %W%`, %H%, 5

There are other characters that also need to be escaped.

这篇关于当消息的文本包含变量时,如何使用带有计时器的AutoHotkey消息框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆