Capture$

Capture function.

The Capture$ function captures in text mode whatever appears in the specified window.

Syntax

a$=Capture$(<window_name>,<instance>,<mode>)

Parameters

<window_name>, window name of the window to be captured, including its <instance>, instance number of the window.

<mode>, integer (constant) corresponding to three bit flags. To obtain the value of <mode>, you have to add the values of each bit set to 1.

Bit 0 (weight 1) specifies how the text is captured :

0

the text is captured as a long string without CRLF

1

each line of the text is captured and separated by CRLF

If this bit is set to 0, the two others are set to 0 (so mode=2, 4 and 6 are invalid and an error is returned at compilation).

Bit 1 (weight 2) specifies the font and its size :

0

the font is not captured

1

the font and size are captured

Bit 2 (weight 4) specifies the underlined and color of the background attributes :

0

these attributes are not captured

1

these attributes are captured

So <mode> can be :

0

the text is captured as a long string without CRLF and attributes

1

the text is captured as several lines without attributes

3

the text is captured as several lines and the font size is captured

5

the text is captured as several lines, the attributes and the color of the background are captured

7

the text is captured as several lines, the fonts and the color of the background are captured

9

special value : mode for capturing text inside an emulator using non-proportional fonts. Use this mode if you notice that the normal mode ignores some blank fields.

Return value

a$, string containing the captured text. If <window_name> or <instance> are not found, or if there is nothing to capture, an empty string is returned.

Remarks

Use the Insert/Statement menu and double click Capture$ in order to automatically generate this statement.

Capture$ tries to capture the text in the order in which this text is displayed on the screen.

Capture$ also works with multiline Editboxes, a single-line EditBox, an entire DialogBox or a static control, if you specify the name of this static in the Capture$ parameters. Use it the same way for capturing the text of icons, buttons, listboxes.

Capture$ does NOT capture the text which overflows the window.

If Capture$ returns an empty string whereas it's really text which is displayed, try this hint:
in the script, copy the desired text to the Clipboard and retrieve after the content of Clipboard - so the statements in the script would be:

'Text selection
SendKeys("<Ctrl a>",NoActivate)
Pause 5 ticks
'Copy the selection to the Clipboard
SendKeys("<Ctrl c>",NoActivate)
Pause 5 ticks
'Retrieve the content of the Clipboard
a$=GetClipboard$()

 

See also

CaptureArea$

CaptureIE$

Example

If you capture this window :

mode 0 returns :

"First line to be capturedSecond line to be capturedThird line to be captured"

mode 1 returns :

"First line to be captured
Second line to be captured
Third line to be captured"

 

mode 3 returns :

|X20,Y4,Times New Roman,H15,L133|First line to be captured
|X20,Y19,Arial,H16,L62|Second
|X82,Y19,Arial,H16,L27|line
|X109,Y19,Arial,H16,L65| to be captured
|X20,Y35,Courier New,H17,L234|Third line to be captured

 

mode 5 returns :

|R0,G0,B0,U0|First line to be captured
|R0,G0,B0,U0|Second
|R0,G0,B0,U1|line
|R0,G0,B0,U0| to be captured
|R0,G0,B0,U0|Third line to be captured

 

mode 7 returns :

|X20,Y4,Times New Roman,H15,L133,R0,G0,B0,U0|First line to be captured
|X20,Y19,Arial,H16,L62,R0,G0,B0,U0|Second
|X82,Y19,Arial,H16,L27,R0,G0,B0,U1|line
|X109,Y19,Arial,H16,L65,R0,G0,B0,U0| to be captured
|X20,Y35,Courier New,H17,L234,R0,G0,B0,U0|Third line to be captured

Information about size, font and location are given below :

n is an integer.

Xn : n = X-axis of the starting point of the text (in pixels), relative to the left edge of the window.

Yn : n = Y-axis of the starting point of the text (in pixels), relative to the top edge of the window.

Hn : n = height of the font (in pixels).

Ln : n = length of the text on the line (in pixels).

With this information, you can find the line and column of the text. For instance, if the first line starts at 4 with a font size of 15, the coordinate of the second column will be 15+4=19. The third line will be at 19+16=35. You can also find the X-axis (if the font is a fixed font) by dividing the length of the text on the line (L) by the number of characters. It gives the width of a character (which is a column).

 

Information about attributes :

n is an integer.

Un : n is 0 or 1 (not underlined or underlined).

Rn, Gn, Bn is for the background color (Red, Green, Blue). n ranges from 0 to 255.

White

255

255

255

Black

0

0

0

Red

255

0

0

Green

0

255

0

Blue

0

0

255

For a mode not equal to 0, if an attribute changes (size, underline, color), a line feed is inserted in the result string.

Performance : Capture$ activates a complex analysis process (0,9 second). If you need more performance, another way can be useful : select text then copy it in the clipboard (via Ctrl+C) then get its content with GetClipboard$

Example code

This script captures the text in WordPad.

 

shell("wordpad")

Pause until 'wait until WordPad is opened

Text("For Help, press F1")

InWindow("WORDPAD.EXE|msctls_statusbar32|Document - WordPad|1",1)

PauseFalse

MsgBox("Pause at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

Msgbox("Write some text in WordPad and press F12")

 

Pause until

Key("<F12>")

PauseFalse

MsgBox("Pause at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

' captures your text in WordPad

text$=Capture$("WORDPAD.EXE|RICHEDIT|Document - WordPad",0,1)

 

msgbox("Your text is : "+text$)