Send keystrokes to the application that has focus. If you combine keystrokes in a single set of braces, you must separate them with a plus operator. Enclosing single-character keystrokes in braces is optional. The SendKeys command is always processed immediately. For example,
SendKeys("{Ctrl+X}")
HardReturn
HardReturn
HardReturn
SendKeys("{Ctrl+V}")
cuts the selected text to the Clipboard (Ctrl+X), inserts three hard returns, and then pastes the contents of the clipboard. (Ctrl+V).
You can also use this command to combine several keystrokes. The following example demonstrates how to create a new file and print it by combining keystrokes.
Display(ON!)
InhibitInput(Off!)
//create a new file
sendkeys("{Alt+F}{n}")
type ("Print this document.")
wait(3)
//prints wpd file
sendkeys ("{Alt+F}{p}{enter}")
Quit
Notes
Keys such as Alt or F1 must be enclosed in braces to specify a single keystroke.
Make sure focus is where it should be. Most errors using SendKeys occur when keys are sent to the wrong place.
Parameters
KeyCode: string The keystrokes to send.
{VKnnn} nnn = ANSI character number
{Alt}
{Ctrl}
{Control}
{Shift}
{0} - {9} Digits
{A} - {Z} Alphabet
{F1} - {F16} Function keys
{NumLock}
{NumAdd}
{NumSubtract}
{NumMultiply}
{NumDivide}
{NumDecimal}
{Num0} - {Num9} Numpad numbers
{Left}
{Right}
{Up}
{Down}
{PgDn}
{PageDown}
{PgUp}
{PageUp}
{Bksp}
{Backspace}
{Break} Cancel
{CapsLock}
{Clear}
{Del}
{Delete}
{End}
{Enter}
{Esc}
{Escape}
{Help} VK Help key
{Home}
{Ins}
{Insert}
{Minus}
{Pause}
{ScrLock}
{ScrollLock}
{PrintScrn}
{PrintScreen}
{Space}
{Tab}
{LeftBrace}
{RightBrace}
MarkupLanguage: enumeration (optional) Specify which language interprets the key codes. Default: New! The values are:
Old!
New!
boolean := SetCurrentDirectory
Example
Syntax
(DirectoryName: string)
Description
Specify a new default directory.
Return Value
Return True if successful, False if not.
Parameters
DirectoryName: string Include the full path.
numeric := SetDefaultParent
Syntax
([Parent: string, or enumeration})
Description
Lets you set or get the handle that you use as the parent window for the Prompt, MessageBox, GetNumber, GetString, and GetUnits commands, and Macro dialogs that don't otherwise specify a parent window.
Return Value
The previous parent window.
Parameter
Parent: string or Enumeration The named region or the window handle of the window to be used as the new default parent for dialogs and prompts. Some enumerations have also been defined to specify certain regions. If missing, NoChange! Is used.
NoChange! Do not set a new default parent. Return the handle of the window of the current default parent.
ResetToOriginal! Restore the default parent to the original parent. The original parent is always the top-level window of the application that started the macro.
Prompts: enumeration (optional) Prompt if attribute does not exist. Default: NoPrompts!
NoPrompts!
Prompts!
boolean := SetFileDateAndTime
Example
Syntax
(Filename: string; [DateAndTime: numeric])
Description
Change the date and time a file was last written to.
Return Value
Return True if successful, False if not.
Parameters
Filename: string Include the full path and filename.
DataType: The type of date and time to set. If missing, ModificationDateTime! is used.
CreationDateTime! Set the date and time the file was created.
LastAccessDateTime! Set the date and time the file was last accessed.
ModificationDateTime! Set the date and time the file was last moi
DateAndTime: numeric (optional) This value is returned from DateAndTime.
numeric := Sign
Syntax
(Value: numeric)
Description
Return the sign of a value.
Return Value
Return -1 if Value is less than 0, 0 if Value equals 0, and 1 if Value is greater than 0.
Parameters
Value: numeric Return the sign of this value.
numeric := sin
Syntax
(Angle: numeric)
Description
Get the sine of an angle in radians.
Return Value
Sine of an angle in radians.
Parameters
Angle: numeric The angle in radians.
numeric := sinh
Syntax
(Angle: numeric)
Description
Get the hyperbolic sine of an angle in radians.
Return Value
Hyperbolic sine of an angle in radians.
Parameters
Angle: numeric The angle in radians.
numeric := SizeOf
Syntax
(Value: any)
Description
Get the size needed to store a specified data value.
This command is mostly used with BinaryPack and BinaryUnpack.
Return Value
Size needed to store a specified data value.
Parameters
Value: any (optional) The value to compute the size of. If missing, the size of the Corel PerfectScript system overhead for storing a value is returned.
Speed
Example
Syntax
(TenthsOfSeconds: numeric)
Description
Slow macro execution.
Time is measured in tenths of a second. Speed(0) runs at maximum speed. Speed(5) delays a macro one-half second between statements. The maximum delay is one minute or Speed(600). The following example delays one second between beeps.
Return Value
The current speed delay value is returned.
Speed(10)
Beep
Beep
Beep
Parameters
TenthsOfSeconds: numeric
(optional) The new speed delay value. If missing, the speed delay is not changed, and the current value is returned. A number from zero to 600. Divide the number by 10 to calculate the number of seconds.
numeric := SquareRoot
Syntax
(Value: numeric)
Description
Get the square root of a value.
Return Value
Square root.
Parameters
Value: numeric The value must be greater than or equal to 0.0.
numeric: StdDev
Syntax
([Type: enumeration]; [Value: numeric])
Description
This command computes the statistical standard deviation of a list of data values.
Return Value
The standard deviation of the data.
Parameters
Type:
enumeration Whether the list of data values represents the entire popluation of data values or just a sample of the data values. If missing, Population! is used.
Population! List is the entire set of data values.
Sample! List represents a sample of all data values.
Value:
numeric The list of data values to compute the standard deviation for.
Step
Syntax
(State: enumeration)
Description
Turn on Macro Debugger single stepping.
See Corel PerfectScript for Help on the debugger itself.
Parameters
State: enumeration Off!
On!
string := String
Syntax
(<Value> string)
Description
Pass a value as an ANSI string (DLL call in-line parameter function and OLE type casting function). See DLLCall and OLE Automation.
string := StrFill
Syntax
(Count: numeric; [String: string])
Description
Fill (replicate) a string a specified number of times.
Examples
vStr := StrFill (2; "PerfectScript")
MessageBox (x; "StrFill"; "..." + vStr + "...")
Result: ...PerfectScriptPerfectScript...
vStr := StrFill (2)
MessageBox (x; "StrFill"; "..." + vStr + "...")
Result: ... ...
Return Value
Replicated string.
Parameters
Count: numeric The number of times to duplicate String. If Count is less than or equal to zero, an empty ("") string is returned.
String: string (optional) The string to repeat. If String is missing, spaces are used.
numeric := StrFraction
Syntax
(String: string)
Description
Get the numeric value of a string representing a fraction.
Examples
vFrac := StrFraction ("1/2")
Result: vFrac = 0.5
vFrac := StrFraction ("187 7/8")
Result: 187.875
Return Value
Numeric value of a string representing a fraction.
Parameters
String: string The string to convert. The form of the string is "n/n" or "n n/n".
SubString: string (optional) The string to insert into String. If missing, characters are removed from String.
Beginning: numeric (optional) The starting position for inserting SubString, or for removing characters from String. If missing, the starting position is the end of the string. If less than zero, the starting position is the absolute value taken from the end of the string. See the example above.
NumberOfChars: numeric (optional) The number of characters replaced by SubString. If SubString is missing, the number of characters to remove from String. If NumberOfChars is missing or equal to zero, no characters are removed. If less than zero, all characters from the starting position to the right are either replaced by SubString or removed.
boolean := StrIsChar
Syntax
(String: string; [Position: numeric]; [Option: enumeration]; [CharSet: string or enumeration])
Description
Determine whether a string or character is of a specified type.
Return Value
True if String is of type CharSet, False if not.
Parameters
String: string The string to test.
Position: numeric (optional) The position of a character to test. If missing or 0, all characters are tested. If greater than the length of String, False is returned. If less than 0, the starting position is the absolute value taken from the end of the string (-1 tests the last character in the string, -2 the second to last character, and so forth).
Option: enumeration (optional) Specify matching criteria. If missing, EqualTo! is used. If CharSet is also missing, NotEqualTo! is used and WhiteSpace! is used for CharSet.
EqualTo! Test for a character in the specified character set.
NotEqualTo! Test for a character that is not in the specified character set.
CharSet: string or enumeration (optional) The set of characters to test. If missing, WhiteSpace! is used. CharSet may be a user-defined character set, specified as a character string expression such as "abcdef", or any combination of the character sets listed below. Type | between enumerations to combine character sets.
Alphabetic!
AlphaNumeric!
Numeric!
Punctuation!
WhiteSpace!
UpperCase!
LowerCase!
string := StrLeft
Syntax
(String: string; [Length: numeric])
Description
Get the left part of a string.
Examples
vStr := StrLeft ("Corel Corporation"; 5)
MessageBox (x; "StrLeft"; "..." + vStr + "...")
Result: ...Corel...
vStr := StrLeft ("Corel Corporation ")
MessageBox (x; "StrLeft"; "..." + vStr + "...")
Result: ...Corel Corporation...
Return Value
Left part of a string.
Parameters
String: string The original string.
Length: numeric (optional) The length of string to return from the left side. If Length is greater than String length, the original string is returned. If Length is 0, an empty ("") string is returned. If Length is missing, or less than or equal to zero, leading whitespace is removed.
numeric := StrLen
Example
Syntax
(String: string)
Description
Return the number of characters in a string.
The string can be a variable, constant, character string, or result of an expression.
Examples
vWord := "WordPerfect"
vNumber := StrLen(vWord)
Result: vNumber equals 11
vNumber := StrLen(45899)
Result: vNumber equals 5
vNumber := StrLen("WordPerfect")
Result: vNumber equals 11
vNumber := StrLen(9 + 9)
Result: vNumber equals 2
Return Value
The number of characters in a string.
Parameters
String: string A variable, constant, character string, or result of an expression.
Separator: string (optional) The string to insert between SubString items. If missing, ";" is used.
Type:
enumeration If a type is specified, the return value is a boolean indicating if the specified value is of the specified type. If missing, CurrentType! Is used.
CurrentType! The actual type of the specified value parameter is returned instead of a boolean value.
SubString: string (repeating)
[optional] The repeating group of items from which to make a list. If missing, returns an empty string.
string := StrNum
Example
Syntax
(String: string)
Description
Convert a character string of numbers to a numeric equivalent.
Return Value
A number.
Examples
vNum := StrNum("123")
Result: vNum = 123
vNum := StrNum("123.5")
Result: vNum = 123.5
vNum := StrNum("9 + 9")
Result: vNum = 9
Parameters
String: string Contains a character string of numbers. StrNum recognizes the decimal point defined by the sDecimal setting in the [intl] section of the Windows WIN.INI file. Alphabetic characters, operators, punctuation marks, and everything that follows them are ignored.
In the following examples, PadString consists of numbers to illustrate the command. Any string of characters, including spaces, could have been used.
vPad := StrPad ("Corel"; 15; PadRight!; "12345")
MessageBox (x; "StrPad"; vPad)
Result: Corel1234512345
vPad := StrPad ("Corel"; 15; PadLeft!; "12345")
MessageBox (x; "StrPad"; vPad)
Result: 1234512345Corel
vPad := StrPad ("Corel"; 15; PadEnds!; "12345")
MessageBox (x; "StrPad"; vPad)
Result: 12345Corel12345
vPad := StrPad ("Corel products are great"; 30; PadWords!; "o")
MessageBox (x; "StrPad"; vPad)
Result: Coooorel prooooducts are great
Return Value
The padded string.
Parameters
String: string The string to be padded.
Length: numeric The final length of the padded string. If the length is less than or equal to zero, or less than the length of String, the original string is returned.
Option: enumeration (optional) Specify where padding is to be added. Default: PadRight!
PadRight! Pad the end of the string.
PadLeft! Pad the front of the string.
PadEnds! Pad both ends, centering the string.
PadWords! Spread the padding between words, expanding String to the specified length. Words must be separated by a character in PadString, or PadEnds! is used.
PadString: string (optional) Multiples of characters in this string pad String to the specified length. PadString may be any string of characters (it is not limited to a single character). If missing, spaces are used. If the string is empty (""), no padding is done. See the examples above.
array := StrParseList
Syntax
(String: string; [Separators: string or enumeration]; [Option: enumeration])
The array of substrings (a substring occupies each array element).
Parameters
String: string The string to parse.
Separators: string or enumeration (optional) Characters or a string that separate(s) the substrings in String. This parameter is either a string of characters or an enumeration that specifies any combination of predefined character sets. It represents individual characters, all of which are used to separate substrings, or as a string (see the Option parameter). If missing, ";" is used.
Punctuation! Separator characters are the set of punctuation characters.
WhiteSpace! Separator charactes are the set of whitespace characters.
Option: enumeration (optional) Lets you specify how to interpret the Separators parameter. If missing, and Separators is a predefined character set, Characters! is used. Otherwise, Strings! is used.
Characters! Any number of individual characters separates substrings in String (see the Separator parameter). Ignores multiple separators.
Strings! An entire string of characters separates substrings in String.
Note
In previous versions of PerfectScript, when there was no data to be returned, a single element array with either a numeric value of 0 or a string value of "" was returned. Now, when there is no data to be returned, an empty array is returned.
Determine whether a character string is also a substring.
Examples
vPos := StrPos("WordPerfect"; "Perfect")
Result: vPos = 5
vPos := StrPos("WordPerfect"; "Scott")
Result: vPos = 0
vPos := CharPos("WordPerfect"; "or"; 7)
Result: vPos = 8
Explanation: Search begins at character position 7, bypassing the first occurrence of the substring.
Return Value
The beginning position of a substring, or zero if a substring is not found.
Parameters
String: string A character string to evaluate.
Substring: string A substring to locate in String parameter.
Beginning: numeric (optional)
Default: 1. Begin looking for Substring at this character position (see the example above).
string := StrReverse
Syntax
(String: string)
Description
Reverse all characters in a string.
Return Value
The string in reverse character order.
Parameters
String: string The original string.
string := StrRight
Syntax
(String: string; [Length: numeric])
Description
Get the right part of a string.
Examples
vStr := StrRight ("Corel Products"; 8)
MessageBox (x; "StrRight"; "..." + vStr + "...")
Result: ...Products...
vStr := StrRight (" Corel Products")
MessageBox (x; "StrRight"; "..." + vStr + "...")
Result: ...Corel Products...
Return Value
Right part of a string.
Parameters
String: string The original string.
Length: numeric (optional) The length of the string to return from the right side. If Length is greater than String length, the original string is returned. If Length is 0, an empty ("") string is returned. If Length is missing, or less than or equal to zero, leading whitespace is removed.
numeric := StrScan
Syntax
(String: string; [Beginning: numeric]; [Option: enumeration]; [CharSet: string or enumeration])
Description
Return the index (position) of the first matching or non-matching character.
Return Value
If no matching or non-matching characters are found, the length of String plus 1 is returned (or 0 if scan was reversed).
Parameters
String: string The string to scan.
Beginning: numeric (optional) The position at which to start the scan. If missing or zero, the starting position is 1. If less than zero, the starting position is the absolute value taken from the end of the string, scanning backwards.
Option: enumeration (optional) Specify matching criteria. If missing, EqualTo! is used. If CharSet is also missing, NotEqualTo! is used and WhiteSpace! is used for CharSet.
EqualTo! Scan until a character in the specified character set is found.
NotEqualTo! Scan until a character not in the specified character set is found.
CharSet: any (optional) The set of characters to match or skip over. If missing, WhiteSpace! is used. CharSet may be a user-defined character set, specified as a character string expression such as "abcdef," or any combination of the predefined character sets listed below. Type | between enumerations to combine character sets.
Alphabetic!
AlphaNumeric!
Numeric!
Punctuation!
WhiteSpace!
UpperCase!
LowerCase!
string := StrToChars
Syntax
(String: string; [Option: enumeration]; [CharSet: string or enumeration])
Option: enumeration (optional) Specify whether characters are to be kept or removed. If missing, Keep! is used. If CharSet is also missing, Remove! is used and WhiteSpace! is used for CharSet.
Keep! Keep specified characters, remove all others.
Remove! Remove specified characters.
CharSet: string or enumeration (optional) The set of characters to keep or remove. If missing, WhiteSpace! is used. CharSet may be a user-defined character set, specified as a character string expression such as "abcdef," or any combination of the predefined character sets listed below. Type | between enumerations to combine character sets.
Convert a string of characters into other characters.
Return Value
Transformed string.
Parameters
String: string The string to transform.
FromChars: string The characters in String to transform.
ToChars: string (optional) The replacement characters. There is a one-to-one correspondence between FromChars and ToChars. Characters in String that are in FromChars are replaced by characters in ToChars in the equivalent positions. For example, the result of
vStr := StrTransform ("12345"; "2345"; "xxxx")
is that "1xxxx" is returned in vStr. If ToChars is missing or shorter than FromChars, all characters are removed from String that match characters in FromChars but have no corresponding character in ToChars.
Options: enumeration (optional) Control the interpretation of FromChars and ToChars, and how many transformations are performed. Default: Characters! | All!
Characters! Transform characters independently.
Strings! Transform the string of characters as a whole.
FirstOnly! Transform only the first occurrence of characters in FromChars.
All! Transform all occurrences of characters in FromChars. Use a number to specify a specific number of occurrences to transform.
string := StrTrim
Syntax
(String: string; [Length: numeric]; [Option: enumeration]; [TrimChars: string or enumeration])
Description
Trim (remove) characters from a string.
Return Value
The string trimmed of characters to a specified length.
Parameters
String: string The string to be trimmed.
Length: numeric (optional) The final length of the trimmed string. If Length is greater than the length of String, no trimming is done and the original string is returned. If Length is missing, or less than or equal to zero, String is trimmed until all matching characters are removed at specified locations (see Options). If the length of String after trimming exceeds Length, no further trimming is done.
Option: enumeration (optional) Specify where String is to be trimmed. Characters matching TrimChars are removed from specified locations until Length is reached, or until no more matching characters are found. Default: TrimRight!
TrimRight! Trim characters from the end of the string.
TrimLeft! Trim characters from the front of the string.
TrimEnds! Trim characters from both ends, centering the string.
TrimWords! Trim multiple characters within String, reducing String to specified length. If the length of String still exceeds Length after trimming multiple characters, the ends are trimmed like TrimEnds!
TrimChars: string or enumeration (optional) The characters to be trimmed from String (all matching characters are removed). If missing, WhiteSpace! is used. TrimChars may be a user-defined character set, specified as a character string expression such as "abcdef," or any combination of the predefined character sets listed below. If TrimChars is empty (""), no trimming is done. Type | between enumerations to combine character sets.
Alphabetic!
AlphaNumeric!
Numeric!
Punctuation!
WhiteSpace!
UpperCase!
LowerCase!
string := Structure
Syntax
(<Value> string)
Description
Pass a value as a C struct (DLL call in-line parameter function and OLE type casting function). See DLLCall and OLE Automation.
numeric := StrUnit
Example
Syntax
(String: string)
Description
Convert a string of numbers to a measurement.
The string may contain a number, an arithmetic expression that results in a number, or a character string of numbers. If a character string is used, alphabetic characters (except units of measure), operators, and punctuation marks are ignored. The default unit of measure is WordPerfect units. You can change the default using DefaultUnits, or by specifying a unit of measure as part of the character string.
Examples
DefaultUnits(Centimeters)
vUnit := STRunIT(9)
Result: vUnit equals 9.C
vUnit := "equals " + StrUnit(4+3)
Result: vUnit equals 7.C
vUnit := "equals " + StrUnit("10")
Result: vUnit equals 10.C
vUnit := "equals " + StrUnit("10abc")
Result: vUnit equals 10.C
vUnit := "equals " + StrUnit("10i")
Result: vUnit equals 10I
The units of measure are:
" inches
i inches
c centimeters
m millimeters
p points (72 per inch)
w WP units (1200 per inch)
Return Value
A unit of measure.
Parameters
String: string A number or character string of numbers.
Value: numeric The list of values. Separate multiple values with a semicolon.
Switch
Example
Syntax
(<Test> any)
Description
A conditional statement that tests for matching expressions. If a match is found, a statement (or statement block) is executed.
If Test matches Selector, the statement block that follows Selector is executed and no other evaluation is made. Test and Selector are case sensitive and must match exactly.
If Continue follows an executed statement block, the next statement block is automatically executed. Continue is optional.
The DEFAULT statement block is executed if no Selector matches Test. DEFAULT is optional. If no match is found and DEFAULT is not used, the macro continues to the first statement after EndSwitch.
If Break occurs in a state block, the macro continues to the first statement after EndSwitch.
EndSwitch closes a Switch statement.
The general form of a Switch statement is:
Switch (<Test>)
CaseOF <Selector>:
...statement block...
Continue
CaseOF <Selector>; <Selector>:
...statement block...
Default:
...statement block...
EndSwitch
Parameters
<Test> any The control expression. Variables are assigned values by commands such as GetString, GetNumber, or Menu.
<Selector> any An expression (variable, constant, character) with a value that is usually assigned before the macro is compiled. It is possible to assign the value at run-time. Selector always follows a CaseOF statement.