C # Analog keyboard operation--sendkey (), SendKeys ()

Source: Internet
Author: User

 

The analog keyboard input is implemented using the following 2 syntaxes.
Sendkeys.send (string keys); Analog kanji (text) input
Sendkeys.sendwait (string keys); Analog Key input

Let's take a look at the usage of the 2 syntax! Post the code later to see if you can read it.

(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. To represent more than one character, you must precede the character with a second character. For example, to represent A, B, and C, you can use "ABC" as a string.

(2) for SendKeys, the plus (+), caret (^), percent sign (%), underscore (~), and parenthesis () have special meanings. To specify any one of these characters, place it in curly braces ({}). For example, to specify a positive sign, you can use {+}. square brackets ([]) do not have a special meaning for SendKeys, but they must be placed in curly braces. In other applications, square brackets have a special meaning, which can be significant in the event of Dynamic Data Exchange (DDE). To specify curly brace characters, use {}.

(3) To specify characters that do not appear when you press a key, such as ENTER or TAB and those that represent an action other than a character, 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}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

(4) Key combinations such as SHIFT, CTRL and ALT can place one or more code in front of these key codes, which are listed as follows:

Keys Code
Shift +
Ctrl ^
Alt %

(5) Input Chinese characters with sendkeys.send ("kanji");

/*----------------The following is the case code-----------------*/

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using System.Windows.Forms; namespace applicationform{public partial class Form1:form {public Form1 () {Initializec        Omponent (); } private void Button1_Click (object sender, EventArgs e) {//cursor moved to RichTextBox1 Richtex             Tbox1.focus ();            Analog Press "ABCDEFG" Sendkeys.sendwait ("(ABCDEFG)");            Sendkeys.sendwait ("{left 5}");             Sendkeys.sendwait ("{h 10}");  /* More examples: sendkeys.sendwait ("^c");  CTRL + C combination key sendkeys.sendwait ("+c");  Shift+c combination Key sendkeys.sendwait ("%c");  Alt+c combination Key sendkeys.sendwait ("+ (AX)");  Shift+a+x combination Key sendkeys.sendwait ("+ax");  Shift+a key combination, then press x sendkeys.sendwait ("{left 5}");   Press ← Key 5 times sendkeys.sendwait ("{h 10}"); //Press H key 10 times sendkeys.send ("kanji"); Analog input "Kanji" 2 Words */}}}

C # Analog keyboard operation--sendkey (), SendKeys ()

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.