How can I use an AutoHotkey message box with a timer when the Text of the message contains variables?

情到浓时终转凉″ 提交于 2020-02-07 04:05:19

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/57467343/how-can-i-use-an-autohotkey-message-box-with-a-timer-when-the-text-of-the-messag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!