PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • How to specify the keystrokes or the mouse actions to perform?
  • Various
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Simulates the keystrokes and the mouse actions. SendKey can send keystrokes or mouse actions to any application intended to be run in a Windows environment.
Caution: In Windows Vista and later, SendKey does not operate properly if the UAC mechanism is enabled: you have the ability to send keys to the current process but to send keys to another process, the application rights must be increased (with a manifest for example).
Example
EXTERN "KeyConst.wl"
i is int
// Runs the Calculator application
ExeRun("Calc.exe", exeActive)
// Wait for the calculator to be loaded
Multitask(50)
// Defines the count loop
FOR i = 1 to 100
// Send the keys to the Calculator application
SendKey(NumToString(i) + "{+}")
END
// Reads the final total
SendKey("=")

// Wait
Multitask(100)

// Sends ALT+F4 to close the Calculator application
SendKey("%{F4}")
// Simulates a right mouse click on a table column
// A table column has no handle so we give it focus to compensate
SetFocus(TABLE_CustomerTable.COL_CustomerName)
// Send the right click
SendKey("{RIGHTBTN,1,1}", TABLE_CustomerTable.COL_CustomerName)
// Expand the "&File" menu of a main window
SendKey("%&f")
// Expand the "&File .. &New" menu of a main window
SendKey("%&fn")
Syntax

Sending keystrokes or mouse actions to a window or to a control identified by its handle Hide the details

<Result> = SendKey(<Key or Mouse> [, <Handle of Window or Control>])
<Result>: Boolean
  • True if the keystrokes were successfully sent,
  • False otherwise.
<Key or Mouse>: Character string
Mouse actions or keystrokes to run. Each key is represented by one or more characters (see the notes).
<Handle of Window or Control>: Optional integer
Handle of window (or control) to which the keystrokes will be sent. If this parameter is not specified, the keystrokes are sent to the current window.
The handle of a window or control is returned by Handle or SysWinHandle.

Sending keystrokes or mouse actions to a window or to a control identified by its name Hide the details

<Result> = SendKey(<Key or Mouse> [, <Name of Window or Control>])
<Result>: Boolean
  • True if the keystrokes were successfully sent,
  • False otherwise.
<Key or Mouse>: Character string
Mouse actions or keystrokes to run. Each key is represented by one or more characters (see the notes).
<Name of Window or Control>: Optional character string
Name or alias of the window (or control) to which the keystrokes must be sent. If this parameter is not specified, the keystrokes are sent to the current window.
Remarks

How to specify the keystrokes or the mouse actions to perform?

The <Key or Mouse> parameter corresponds to the mouse actions or to the keystrokes used to run the shortcut. Each key is represented by one or more characters. There is no need to specify "Ctrl-Alt" that is automatically added. No shortcut key is specified by default.
To use a single keyboard character, you must use the character itself. For example, to represent the letter A, assign the value "A" to <Key or Mouse>. To use a set of characters, use the set of characters directly ("ADB").
Caution: A special meaning is assigned by the function to the following characters:
  • plus (+),
  • insertion (^),
  • percentage (%),
  • brackets ( ).
To use one of these characters, the character must be enclosed in curly brackets. For example, to use the plus sign (+), type {+}. To use curly brackets, use the {{} and {}} characters.
To use special characters, specific codes are required to identify:
  • the characters with no action on the screen (the Enter key for example)
  • the characters corresponding to an action (the function keys for example).
You must use the following codes:
KeyCodeKeyCode
BACKSPACE{RA}PAUSE{PAUSE}
CAPSLOCK{VERRMAJ}DEL{SUPPR}
DOWN{DOWN}END{END}
ENTER{ENTER}ESC{ECHAP}
HELP{HELP}HOME{HOME}
INSERT{INS}LEFT{LEFT}
NUMLOCK{NUMLOCK}PGDN{PGDN}
PGUP{PGUP}PRNT. SCREEN{PRTSC}
RIGHT{RIGHT}SCROLLLOCK{SCROLLLOCK}
TAB{TAB}TOP{TOP}
F1{F1}F2{F2}
F3{F3}F4{F4}
F5{F5}F6{F6}
F7{F7}F8{F8}
F9{F9}F10{F10}
F11{F11}F12{F12}
F13{F13}F14{F14}
F15{F15}F16{F16}
+ on the numeric keypad{NUM+}- on the numeric keypad{NUM-}
To specify a key combination with MAJ, CTRL or ALT, the standard code of the key must be preceded by one or more codes among the following ones:
KeyCode
SHIFT+
CTRL^
ALT%
To specify that the MAJ, CTRL and/or ALT key must be kept down while pressing another key: for example, in order for the SHIFT key to be kept down while pressing the E key, use "+e".
To specify that a key must be repeated, you must use an expression such as {<Key> <Number>}. Note: a space character is required between <Key> and <Number>. For example:
  • {LEFT 42} means that the Left key must be pressed 42 times,
  • {h 10} means that the h key must be pressed 10 times.
To specify the operations performed with the mouse, you must use the following codes:
OperationCode
Click with left mouse button{LEFTBTN[,x[,y]]}
Double click with left mouse button{LEFTBTN2[,x[,y]]}
Left mouse button down{LEFTBTN+[,x[,y]]}
Left mouse button up{LEFTBTN-[,x[,y]]}
Click with right mouse button{RIGHTBTN[,x[,y]]}
Double click with right mouse button{RIGHTBTN2[,x[,y]]}
Right mouse button down{RIGHTBTN+[,x[,y]]}
Right mouse button up{RIGHTBTN-[,x[,y]]}
Click with middle mouse button{MIDDLEBTN[,x[,y]]}
Double click with middle mouse button{MIDDLEBTN2[,x[,y]]}
Middle mouse button down{MIDDLEBTN+[,x[,y]]}
Middle mouse button up{MIDDLEBTN-[,x[,y]]}
Mouse movements{MOUSE[,x[,y]]}
x and y are respectively the X coordinates and the Y coordinates in relation to the client area of the destination window. If x or y is not specified, the value used is 0.

Various

  • SendKey cannot send the [Print Screen] key to an application.
  • Java SendKey can send the [Print Screen] key to an application.
  • In Windows Vista (and later), SendKey does not operate properly if the UAC is enabled.
  • SendKey takes the current keyboard into account (modified by ChangeKeyboard): the characters sent depend on the keyboard used.
  • SendKey does not operate on a non-interactive TSE session.
Related Examples:
The SendKey function Unit examples (WINDEV): The SendKey function
[ + ] Sending keystrokes to an application with the WLanguage functions.
The following topics are presented in this example:
1/ SendKey() function
2/ System functions
This example explains how to control an application by sending keystrokes to it.
A WINDEV application can directly handle external applications such as Word via OLE Automation or DDE.
For the applications that do not support these types of links, you have the ability to simulate keystrokes via the SendKey function in order to control these applications.
Components
WINDEVReports and Queries wd230std.dll
Java wd230java.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment