Home > Language Reference > Capture Functions > Capture$


The Capture$ function returns the text found in the specified window.


Used to test the content of a window.

Video: How to capture the whole content of a window using Capture$ WinTask function. The SplitIntoArray function is then used to split the long captured string.


var$=Capture$(<window_name>, <mode>)


<window_name>, string, name of the window to capture. The <window_name> must include the instance number.
<mode>, integer, constant only, sum of three bit flags. The possible values for each bit are:

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: 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 font and size are captured
5: the text is captured as several lines, the attributes and the color of background are captured
7: the text is captured a several lines, font, size, attributes and color of background are captured
9: special value, the text is captured inside an emulator software using non-proportional fonts. Use this mode if the other modes ignore some blank fields.

Return value

var$, string. It contains the captured text. If <window_name> is not found, or if there is nothing to capture, an empty string is returned (an emty string is "").


Generate the Capture$ syntax using its wizard: in the Language pane of the WinTask Editor, double-click the Capture$ function name to start the wizard (if the Language pane is not displayed, press F4 or select Insert/Statement menu).

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 there is a displayed text, use Clipboard to retrieve the content of the window. 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

PERFORMANCE: Capture$ activates a complex analysis process (0.9 second). If you need better performance, you can automate those steps:
select text then copy it into the clipboard (via Ctrl+C) then get its content with GetClipBoard$ function.

See also



With such a WordPad window (launch wordpad.exe located in C:\Program Files (x86)\Windows NT\Accessories):

mode 0 returns:
First line to captureSecond line to captureThird line to capture

mode 1 returns:
First line to capture
Second line to capture
Third line to capture

mode 3 returns:
|X20,Y4,Times New Roman,H15,L133|First line to capture
|X109,Y19,Arial,H16,L65| to capture
|X20,Y35,Courier New,H17,L234|Third line to capture

 mode 5 returns:
|R0,G0,B0,U0|First line to capture
|R0,G0,B0,U0| to capture
|R0,G0,B0,U0|Third line to capture
mode 7 returns :
|X20,Y4,Times New Roman,H15,L133,R0,G0,B0,U0|First line to capture
|X109,Y19,Arial,H16,L65,R0,G0,B0,U0| to capture
|X20,Y35,Courier New,H17,L234,R0,G0,B0,U0|Third line to capture

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.
 Color R value   G value  B value
 White  255  255  255
 Black  0  0  0
 Red  255  0  0
 Green  0  255  0
 Blue  0  0  255


'This script captures the text that you typed into WordPad.
Shell(Chr$(34)+"C:\Program Files (x86)\Windows NT\Accessories\wordpad.exe"+Chr$(34),1)
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad")  'UseWindow waits until the wordpad window is displayed
Msgbox("Write some text in WordPad and press F12")
'Wait until F12 has been pressed
Pause until
MsgBox("Pause at line " + #ErrorLine$ + " has failed !",16,"Runtime error")
' captures the text that you typed in WordPad
text$=Capture$("WORDPAD.EXE|RICHEDIT50W|Document - WordPad",1,1)
msgbox("Your text is : "+text$)