VB6Parse / Library / System Interaction / sendkeys

VB6 Library Reference

SendKeys Statement

Sends one or more keystrokes to the active window as if typed at the keyboard.

Syntax

SendKeys string [, wait]

Parts

Remarks

Special Key Codes

Key Code
BACKSPACE {BACKSPACE} or {BS} or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC} or {ESCAPE}
HELP {HELP}
HOME {HOME}
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-F16 {F1} through {F16}

Modifier Keys

Key Code
SHIFT + (plus sign)
CTRL ^ (caret)
ALT % (percent sign)

To specify modifier keys with regular keys, enclose the regular keys in parentheses: - "+{F1}" sends SHIFT+F1 - "^(ec)" sends CTRL+E followed by CTRL+C - "%(FA)" sends ALT+F followed by ALT+A

Repeating Keys

To repeat a key, use the format {key number}: - "{RIGHT 10}" sends RIGHT arrow 10 times - "{TAB 5}" sends TAB 5 times

Examples

Send Simple Text

SendKeys "Hello World"

Send Text with Enter Key

SendKeys "Username{TAB}Password{ENTER}"

Activate Window and Send Keys

AppActivate "Notepad"
SendKeys "Hello from VB6{ENTER}", True

Send Alt+F4 to Close Window

SendKeys "%{F4}"  ' ALT+F4

Send Ctrl+C to Copy

SendKeys "^c"  ' CTRL+C

Send Multiple Keys with Wait

SendKeys "{DOWN}{DOWN}{ENTER}", True

Fill Form Fields

AppActivate "Data Entry Form"
SendKeys "John Doe{TAB}123 Main St{TAB}555-1234{ENTER}", True

Send Function Keys

SendKeys "{F1}"    ' Help key
SendKeys "{F5}"    ' Refresh
SendKeys "+{F10}"  ' SHIFT+F10 (context menu)

Repeat Keys

SendKeys "{RIGHT 5}"    ' Move right 5 times
SendKeys "{DOWN 10}"    ' Move down 10 times
SendKeys "{BACKSPACE 3}" ' Delete 3 characters

Send Key Combinations

SendKeys "^a"       ' CTRL+A (Select All)
SendKeys "^c"       ' CTRL+C (Copy)
SendKeys "^v"       ' CTRL+V (Paste)
SendKeys "^s"       ' CTRL+S (Save)
AppActivate "Microsoft Word"
SendKeys "%f", True  ' ALT+F (File menu)
SendKeys "s", True   ' S (Save)

Send Special Characters

SendKeys "Test {+} Addition"  ' Sends: Test + Addition
SendKeys "Test {^} Power"     ' Sends: Test ^ Power
SendKeys "Test {% } Percent"  ' Sends: Test % Percent

Important Notes

Common Errors

Best Practices

See Also

References

← Back to System Interaction | View all statements