How to extract texts displayed in MsgBox without the markers?

Get help with using AutoHotkey and its commands and hotkeys
llinfeng
Posts: 64
Joined: 08 Dec 2016, 21:54
GitHub: llinfeng

How to extract texts displayed in MsgBox without the markers?

06 Apr 2020, 11:40

Can I add some option to MsgBox, so that I can Copy (with ctrl+v) from its message box ONLY the input that I have fed to it? For now, I am using Vim macros to clean up the markers around the real contents of interest. A typical clipboard content obtained by pressing ctrl+v in a MsgBox window:
---------------------------
ahk_master.ahk
---------------------------
"XXXXXX___This_Line_is_of_interest_XXXXXX"
---------------------------
OK
---------------------------

From the documentation page for MsgBox, there is a tip mentioning: "Tip: Pressing ctrl+c while a MsgBox window is active will copy its text to the clipboard. This applies to all MsgBoxes, not just those produced by AutoHotkey." ==> Yet, as shown above, the copied contents are formatted with window_title and an OK button, along with a few horizontal divider lines. The following subroutine can reproduce the message above. (I would like to keep the "OK" button to make sure the MsgBox won't go away before I get a chance to *copy* from it for its text.)

Code: Select all

test_clipboard:
    StrOfInterest="XXXXXX___This_Line_is_of_interest_XXXXXX"
    MsgBox, %StrOfInterest%
return
Background: I find a potential problem with updating the clipboard using some existing variables. The characters with GBK encoding (Chinese characters) are "clipped" wrongly. The variables themselves were displayed normally when rendered through MsgBox. Yet, pasting from ClipBoard with ctrl+v after refreshing the clipboard with Clipboard := var_content shall replace all the GBK-encoded characters with one or two question mark(s). Since the problem appears to be with GBK-characters only, I have posted here and here in the Chinese forum.
User avatar
Chunjee
Posts: 446
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: How to extract texts displayed in MsgBox without the markers?

06 Apr 2020, 12:03

I am interested in this as well. Don't see the need for all the extra formatting
User avatar
boiler
Posts: 4668
Joined: 21 Dec 2014, 02:44

Re: How to extract texts displayed in MsgBox without the markers?

06 Apr 2020, 12:25

Have this script running, and it will automatically clean up the Clipboard when you copy that format from a MsgBox.

Code: Select all

#Persistent
OnClipboardChange("CleanMsgBox")
return

CleanMsgBox() {
	if WinActive("ahk_class #32770")
		Clipboard := RegExReplace(Clipboard, "s)\v*---------------------------.*?---------------------------\v*")
}
I suppose you are already doing something like this with your Vim macros, but it sounds like you are looking for an AHK solution. There won't be one that changes what gets copied to the MsgBox with a code or option because it's not an AHK issue. MsgBoxes produced by other programs will also add the title and button info along with separator lines because it's an OS-level issue.
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: How to extract texts displayed in MsgBox without the markers?

06 Apr 2020, 12:57

You can try
WinGetText
instead of the clipboard.

Return to “Ask For Help”

Who is online

Users browsing this forum: GoBackSin, Google [Bot], JoeWinograd, Smile_, vlakmire and 97 guests