Home > Language Reference > Capture Functions > HardCopy


The HardCopy function takes a screenshot of the entire screen or of the active window and saves is as a .BMP or .JPG file.


Used for debugging purposes : you can capture the entire screen at some points during execution of the script. See the script example below to take a screenshot each time an execution error occurs.


ret=HardCopy(<filename>, 1|2 [, <option>])


<filename>, string, name of the file (extension .BMP or .JPG) into which the captured image is saved. If no extension is specified, .BMP is added.
1|2, integer, 1 or 2, 1 to capture the entire screen, 2 to capture only the active window.

<option>, integer, constant, sum of those values:
0    The file is generated without any option
1    A time stamp is added to the filename; the timestamp format is hhmmss (eg. with <filename> : "screenshot.jpg" and hardcopy done at 3:45:34 pm, result file is "screenshot154534.jpg")
2    The filename is incremented at each execution
4    The screenshot is done in black and white
for example, if <option> is at 3, the filename will include a timestamp and will increment at each execution.

Return value

ret, integer, optional return code. If the hardcopy is successfully done, the return value is 0. If the function fails, the return value is a nonzero value (see File Functions Error Codes).

See also



HardCopy("C:\program files (x86)\wintask\scripts\screenshot.jpg",1,2) 'captures the entire screen and increments at each execution the filename (screenshot1.jpg, screenshot2.jpg, ... will be created).

'In this script, a hardcopy is done when a script execution error occurs 
'Definition of the proc to call if an error is detected.
Sub Process_Error()
local buffer$ 
'If within this proc, an error occurs too, it generates an infinite loop as
'the call to the error proce causes an error. To avoid that, we disable OnAction Error within this proc.
'Take a screenshot of the desktop
ret=Hardcopy("C:\program files (x86)\wintask\scripts\error.jpg",1,1) 
'Here a part for writing in a txt file where we were in the script, the error code, the error message when the error occurred.
buffer$="Error in : "+#ErrorScript$
write("C:\program files (x86)\wintask\scripts\error.txt",buffer$,crlf)
buffer$="Error line : "+str$(#LastErrorLine)
write("C:\program files (x86)\wintask\scripts\error.txt",buffer$,crlf)
buffer$="Error Code : "+str$(#Errorcode)
write("C:\program files (x86)\wintask\scripts\error.txt",buffer$,crlf)
buffer$="Error Function : "+#ErrorFunction$
write("C:\program files (x86)\wintask\scripts\error.txt",buffer$,crlf)
buffer$="Error message : "+#ErrorMsg$
write("C:\program files (x86)\wintask\scripts\error.txt",buffer$,crlf)
'Add here other lines for what to do in case of an error.
'OnAction Error triggers and calls the Process_Error Sub when an execution error occurs 
OnAction error
dosub Process_Error
'The window is not found, so OnAction error triggers.