C # How to Use SendKeys

Source: Internet
Author: User

Function: send one or more key messages to the activity window, just like inputting on the keyboard.

Syntax: SendKeys. Send (string keys); SendKeys. SendWait (string keys );

Note:

(1) Each key is represented by one or more characters. To specify a single keyboard character, you must press the character key. For example, to represent the letter A, you can use "A" as the string. To indicate multiple characters, you must add another character directly after the character. For example, to indicate a, B, and C, "ABC" can be used as A string.

(2) For SendKeys, the plus sign (+), the insert character (^), the percentage sign (%), and the upper line (~) And parentheses () have special significance. To specify any of the preceding characters, place them in braces. For example, to specify a positive number, it can be represented by {+. Square brackets ([]) do not have special significance for SendKeys, but must be placed in braces. Square brackets are of special significance in other applications. When Dynamic Data Exchange (DDE) occurs, it may be of great significance. To specify braces, use {} and {}}.

(3) Use the following code to specify characters that are not displayed when you press the button, such as ENTER or TAB, and keys that represent actions rather than characters:

Buttons Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} Or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F1}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

(4) To specify the key combinations that combine with the SHIFT, CTRL, and ALT keys, you can place one or more codes in front of these key codes. These codes are listed as follows:

Buttons Code
Shift +
Ctrl ^
Alt %

To show that you should press any combination of SHIFT, CTRL, and ALT at the same time when pressing other keys, please put the code of those keys in brackets. For example, to demonstrate how to press the Shift key while pressing E and C, use "+ (EC )". "+ EC" is used to indicate that the SHIFT key is pressed at the same time while the C key is pressed instead of the SHIFT key ".
To specify duplicate keys, use the {key number} format. A space must be placed between the key and number. For example, {LEFT 42} Means 42 times to press the left arrow key; {h 10} means 10 times to press the H key.
Note: you cannot use SendKeys to send a key message to an application that is not designed to run in Microsoft Windows. Sendkeys cannot send the print screen button {PRTSC} to any application either.

(5) Use SendKeys. Send ("") to input Chinese characters ");

Article Reprinted from: http://www.cnblogs.com/sydeveloper

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.