HardCopy

Capture function.

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

Usage

HardCopy function can be used for debugging purposes : you can capture the entire screen at some points during execution of the script. Use HardCopy wizard to generate the function easily (to access the wizard, press F4 to display the Language window and in Capture Instructions chapter, double click the HardCopy function). See the script example below to take a screenshot if an execution error happens

Syntax

HardCopy(<filename>,<screenshot_type>[,<option>])
or
ret=HardCopy(<filename>,<screenshot_type>[,<option>])

Parameters

<filename>, name of the file (extension .BMP or .JPG) into which the captured image is saved. If no extension is specified, .BMP is added.

<screenshot_type> : integer, 1 to capture the entire screen, 2 to capture only the active window.

<option>, optional integer, specifying some options. <option> cannot be a variable. It is the 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 (for example, if filename is "screenshot.jpg" and the hardcopy is done at 3:45:34 pm, the hardcopy function will generate this filename : "screenshot154534.jpg")

2

The filename is incremented at each execution

4

The image is captured in black and white

So for example, if <option> is at 3, the filename will include a timestamp and will increment when the capture is done.

Return value

Ret, numeric return code. When successful, the function returns 0, otherwise use this return code for error management.

Example

 

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

Example code

 

'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.

disable(Error)

'Take a screenshot of the desktop

ret=Hardcopy("C:\program files\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\wintask\scripts\error.txt",buffer$,crlf)

buffer$="Error line : "+str$(#LastErrorLine)

write("C:\program files\wintask\scripts\error.txt",buffer$,crlf)

buffer$="Error Code : "+str$(#Errorcode)

write("C:\program files\wintask\scripts\error.txt",buffer$,crlf)

buffer$="Error Function : "+#ErrorFunction$

write("C:\program files\wintask\scripts\error.txt",buffer$,crlf)

buffer$="Error message : "+#ErrorMsg$

write("C:\program files\wintask\scripts\error.txt",buffer$,crlf)

 

 

'Add here other lines for what to do in case of an error.

'......

 

Endsub

 

 

OnAction error

dosub Process_Error

endaction

 

#Actiontimeout=15

'The window is not found, so OnAction error triggers.

UseWindow("toto")