当消息的文本包含变量时,如何使用带有计时器的 AutoHotkey 消息框?
How can I use an AutoHotkey message box with a timer when the Text of the message contains variables?
在调试 AHK 脚本时,我喜欢添加 MsgBox 语句以帮助我知道已到达一段代码,并且我可能希望在消息中包含一些变量。我希望消息框有一个超时,以便它在 5 秒后自动关闭。我想坚持使用消息框,而不是使用工具提示或依赖我需要包含在脚本中的函数。
我正在寻找单行代码,这样我就可以在不需要时轻松地将其注释掉。
我遇到的问题是将多个变量传递给 MsgBox 的 Text 参数将它与 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
还有其他字符也需要escaped。
在调试 AHK 脚本时,我喜欢添加 MsgBox 语句以帮助我知道已到达一段代码,并且我可能希望在消息中包含一些变量。我希望消息框有一个超时,以便它在 5 秒后自动关闭。我想坚持使用消息框,而不是使用工具提示或依赖我需要包含在脚本中的函数。
我正在寻找单行代码,这样我就可以在不需要时轻松地将其注释掉。
我遇到的问题是将多个变量传递给 MsgBox 的 Text 参数将它与 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
还有其他字符也需要escaped。