SendKeys
The SendKeys
method allows the user to send keystrokes and combinations to a Control or Page Object.
Sending special keys
You can send some special keys to controls using the Keys
class.
The Keys
class contains the following special keys categories:
Function Keys.
Navigation Keys.
System Keys.
Numeric Keys
Editing keys.
Lock keys.
Modifier Keys
The following is an example of the use of the Keys
class:
Key Combinations
The SendKeys method can be used to simulate hotkeys and accelerator keys on a control.
How to use
You have to enclose them in brackets ([])
, one or more modifier keys such as ctrl
, alt
or shift
with at least one character or special key. For example:
To escape braces and brackets, you need to write them twice, for example:
"[["
.Any key or special key enclosed on the brackets will have the specified modifiers active.
SendKeys vs. Text
Some controls have the settable Text
property which can be used instead of SendKeys
. There is one major difference between these two methods: SendKeys
will press each key from the string passed onto it as if performed by a human. On the other hand,Text
is only concerned with replacing the text on the control by any means necessary. In practice this means that SendKeys
is guaranteed to raise browser or OS key-press events, whereas Text
is not.
Last updated