ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous Windows functions
  • How to specify the keystrokes or the mouse actions to perform?
  • Miscellaneous
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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: On Windows Vista and higher, if the UAC mechanism is enabled, SendKey does not work properly: 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 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{BS}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 Shift, Ctrl or Alt, the standard key code must be preceded by one or more codes chosen among the following ones:
KeyCode
SHIFT+
Ctrl^
ALT%

To specify that the Shift, Ctrl and/or Alt keys must be hold 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>}. Remark: 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 destination window. If x or y is not specified, the value used is 0.

Miscellaneous

  • 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 work on a non-interactive TSE session.
Component: wd290std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Capturando a tela e salvando no banco de dados
Global init project

// Include the "KeyConst.wl" file to manage the keyboard keys
EXTERN "KeyConst.WL"

In Button

Sendkey(“{PTRSC}”)

Clipboard(img_tela_capturada)

Tabela.screen = img_tela_capturada

Tabela.datahora = datesys()+timesys()

Hadd(Tabela)

Compile e teste esses comandos

Vai pressionar a tecla printscreen e salvar no banco a imagem

Precisa que seja compilado para funcionar
Boller
23 Aug. 2023

Last update: 07/17/2023

Send a report | Local help