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 () {
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
Move cursor to RichTextBox1
Richtextbox1.focus ();
Analog Press "ABCDEFG"
Sendkeys.sendwait ("(ABCDEFG)");
Sendkeys.sendwait ("{left 5}");
Sendkeys.sendwait ("{h 10}");
/*
More examples:
Sendkeys.sendwait ("^c");
CTRL + C key combination
Sendkeys.sendwait ("+c");
Shift+c Key Combinations
Sendkeys.sendwait ("%c");
Alt+c Key Combinations
Sendkeys.sendwait ("+ (AX)");
Shift+a+x Key Combinations
Sendkeys.sendwait ("+ax");
Shift+a key combination, then press the X key
Sendkeys.sendwait ("{left 5}");
Press the ← 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 ()