http://www.codeproject.com/KB/cpp/sendkeys_cpp_Article.aspx
The following table is a slightly modified version of the MSDN/SendKeys help:
| 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 | {INS} |
| LEFT ARROW | {LEFT} |
| NUM LOCK | {NUMLOCK} |
| PAGE DOWN | {PGDN} |
| PAGE UP | {PGUP} |
| PRINT SCREEN | {PRINTSCREEN} |
| RIGHT ARROW | {RIGHT} |
| SCROLL LOCK | {SCROLL} |
| 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 | {F11} |
| F12 | {F12} |
| F13 | {F13} |
| F14 | {F14} |
| F15 | {F15} |
| F16 | {F16} |
| Keypad add | {ADD} |
| Keypad subtract | {SUBTRACT} |
| Keypad multiply | {MULTIPLY} |
| Keypad divide | {DIVIDE} |
(table 1.a)
The following are my additions:
| Key | Code |
| + | {PLUS} |
| @ | {AT} |
| APPS | {APPS} |
| ^ | {CARET} |
| ~ | {TILDE} |
| { } | {LEFTBRACE} {RIGHTBRACE} |
| ( ) | {LEFTPAREN} {RIGHTPAREN} |
| Left/Right WINKEY | {LWIN} {RWIN} |
| WINKEY | {WIN} equivalent to {LWIN} |
(table 1.b)
In addition to this, I have added some special keys that act like commands:
| Command Syntax | Action |
| {VKEY X} | Sends the VKEY of value X. Very useful if you don't want to recompile CSendKeys and add new Vkey to the hardcoded special keys table. For example, {VKEY 13} is equivalent to VK_RETURN. |
| {BEEP X Y}} | Beeps with a frequency of X and a duration of Y milliseconds. |
| {DELAY X} | Delays sending the next key of X milliseconds. After the delaying the following key, the subsequent keys will not be further delayed unless there is a default delay value (see DELAY=X). Example: {DELAY 1000} <-- delays subsequent key stroke for 1 second. |
| {DELAY=X} | Sets the default delay value to X milliseconds. This will cause every key to be delayed X ms. If a value is already set and you specify {DELAY Y} you will have your following key delay Y ms but the subsequent keys will be delayed X ms. Example: {DELAY=1000} <-- all subsequent keys will be delayed for 1 second. |
| {APPACTIVATE WindowTitle} | Activates an application using is WindowTitle. Very useful if you want to send different keys to different applications. |
(table 2)
| Code | |
| WINKEY | @ |
| SHIFT | + |
| CTRL | ^ |
| ALT | % |
(table 3)
Here are some examples:
| Keystrokes | Description |
| {DELAY=50}@rnotepad~hello world%ha |
|
| {delay=100}{appactivate Calculator}{ESC}5*7~{beep 1000 500}^c{appactivate Notepad}^a{DEL}Result of 5*7 is: ^v | Given that "Calc.exe" and "Notepad.exe" are running:
|
| {DELAY=500}{NUMLOCK}{CAPSLOCK}{SCROLL}{SCROLL}{CAPSLOCK}{NUMLOCK} |
|
| {DELAY=500}% {DOWN 5} |
|
本文详细介绍了如何使用SendKeys发送各种键盘按键,包括特殊键、功能键等,并提供了多个实际应用场景的例子,如激活应用程序窗口、输入文本及执行快捷键操作。
846

被折叠的 条评论
为什么被折叠?



