C # SendKeys Introduction to using _c# Tutorial

Source: Internet
Author: User

Function: Sends one or more key messages to the active window as if you were typing on a keyboard.

Syntax: Sendkeys.send (string keys); Sendkeys.sendwait (string keys);

Description

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

(2) for SendKeys, the plus sign (+), the caret (^), the percent sign (%), the underscore (~), and the parentheses () all have special meanings. To specify any of these characters, place it in braces ({}). For example, to specify a plus sign, you can use {+}. square brackets ([]) are not of special significance to SendKeys, but they must be placed in curly braces. In other applications, square brackets have special meaning, which can be significant when Dynamic data exchange (DDE) occurs. To specify curly braces characters, use {{} and {}}.

(3) to specify characters that are not displayed when the key is pressed, such as ENTER or TAB, and those that represent actions rather than characters, use the following code:

Keys 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}
h1| {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}


(4) In order to specify those key combinations with SHIFT, CTRL, and ALT keys, you can place one or more code in front of these key codes, which are listed as follows:

Keys Code
Shift +
Ctrl ^
Alt %

To indicate that you should press SHIFT, CTRL, and ALT at the same time when you press the other keys, put those keys in parentheses. For example, to indicate that you press the SHIFT key while pressing E and C, use "+ (EC)". To show that you press the SHIFT key while pressing E, but then press C instead of shift, use "+EC".
To specify a duplicate key, use the form {key number}. A space must be placed between key and number. For example, {left 42} means to press the arrow key 42 times, and {h 10} means 10 times to press the H key.
Note: You cannot use SendKeys to send key messages to an application that is not designed to run in Microsoft Windows. SendKeys also cannot send print Screen key {PRTSC} to any application.

(5) Inputting Chinese characters with Sendkeys.send ("Chinese characters");

Article reproduced from: Http://www.cnblogs.com/sydeveloper

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.