|
|
|
|
|
- How to specify the keystrokes or the mouse actions to perform?
- Miscellaneous
SendKey (Function) In french: EnvoieTouche 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. Attention: Under Windows Vista and above, if the UAC mechanism is enabled, the SendKey function does not work correctly: it is possible to send keys to the current process, but to send keys to another process, it is necessary to raise the application's rights (with a manifest, for example). EXTERN "KeyConst.wl"
i is int
ExeRun("Calc.exe", exeActive)
Multitask(50)
FOR i = 1 TO 100
SendKey(NumToString(i) + "{+}")
END
SendKey("=")
Multitask(100)
SendKey("%{F4}")
SetFocus(TABLE_TableClient.COL_NomClient)
SendKey("{BTNDROIT,1,1}", TABLE_TableClient.COL_NomClient)
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.
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: The function gives a special meaning to the following signs: - 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: | | | | Key | Code | Key | Code |
---|
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: To specify that the Shift, Ctrl and/or Alt keys are held down while another key is pressed: for example, to hold down the Shift key at the same time as the E key, use "+e". To specify that a key must be repeated, you must use an expression such as {<Key> <Number>}. Note: There must be a space between the <Touche> and <Nombre>parameters. . 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: | | Operation | Code |
---|
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.
- SendKey can send the Print Screen key. to an application.
- In Windows Vista (and later), SendKey does not work properly if the UAC is enabled.
- The SendKey function takes into account the current keyboard (modified by the ChangeKeyboard function): the characters sent depend on the keyboard used.
- SendKey does not work on a non-interactive TSE session.
Related Examples:
|
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.
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|