Introduction to the use of C SendKeys

  • 2020-05-09 19:11:46
  • OfStack

Function: send one or more key messages to the active window, just like typing 1 on the keyboard.

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

Description:

(1) each key is represented by one or more characters. 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 string. To represent multiple characters, you must add another character directly after the character. For example, to represent A, B, and C, you can use "ABC" as 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 the above characters, place it in braces ({}). For example, to specify a plus sign, it can be represented by {+}. Square brackets ([]) do not have special meaning for SendKeys, but they must be placed in curly brackets. In other applications, square brackets have special meaning and can be significant when dynamic data exchange (DDE) occurs. To specify the curly brace characters, use {{} and {}}.

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

The 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) to specify key combinations that are combined with buttons such as SHIFT, CTRL, and ALT, one or more codes can be placed in front of these key codes, which are listed below:

The keys code Shift + Ctrl ^ Alt %

To indicate that any key combinations of SHIFT, CTRL, and ALT should be pressed at the same time as other keys, place the lines of those keys in brackets. For example, to show that when pressing E and C, press Shift at the same time, use "+(EC)". To show that when pressing E and pressing SHIFT at the same time, but then pressing C instead of SHIFT, "+EC" is used.
To specify duplicate keys, use the form {key number}. You must place a space between key and number. For example, {LEFT 42} means to press LEFT ARROW 42 times; {h 10} means pressing H 10 times.
Note: key messages cannot be sent to such an application using SendKeys, which is not designed to run in Microsoft Windows. Sendkeys also cannot send the PRINT SCREEN button {PRTSC} to any application.

(5) input Chinese characters with SendKeys.Send(" Chinese characters ");

The article reprinted from: http:. / / www cnblogs. com/sydeveloper


Related articles: