LocationMy.Computer.Keyboard.SendKeys SyntaxMy.Computer.Keyboard.SendKeys(keys[, wait])
DescriptionThe SendKeys method simulates the typing of one or more keys in the active window. To send plain text, simply include that text in the keys argument. For instance, using "abc" for the keys argument will send the characters a, b, and c, one at a time, to the active window. To have the Shift key held down with a key, precede that key with a plus sign (+). To use the Control key with another key, precede that key with the caret (^). To use the Alt key with another key, precede that key with the percent sign (%). To use one of these special keys with multiple other keys, enclose those other keys in parentheses. For instance, "+(abc)" sends a, b, and c with the Shift key held down. You can repeat a key multiple times by using the syntax "{key count}" (that is, the character, then a space, then a numeric value, all within braces). For example, "{a 25}" will send the "a" key 25 times. SendKeys supports several special keys, such as the Left Arrow key. Also, some standard keys must be enclosed in a set of braces to be recognized as a standard key. The following table lists all of these special keys and special-use standard keys.
Usage at a Glance
ExampleThe following example starts up Notepad, adds some text to its editing area, copies that text to the clipboard, and exits the program without saving changes. Dim notepadID As Integer ' ----- Start and activate the Notepad application. notepadID = Shell("notepad.exe", AppWinStyle.NormalFocus) AppActivate(notepadID) My.Application.DoEvents( ) ' ----- Add some text. My.Computer.Keyboard.SendKeys("+visual +basic~", True) My.Computer.Keyboard.SendKeys("{- 12}~", True) My.Computer.Keyboard.SendKeys("+it's fun{!}", True) ' ----- Select all text with Control+A, then copy with Control+C. My.Computer.Keyboard.SendKeys("^(a)", True) My.Computer.Keyboard.SendKeys("^(c)", True) ' ----- Quit Notepad. My.Computer.Keyboard.SendKeys("%{F4}", True) My.Computer.Keyboard.SendKeys("n", True) ' ----- See if we copied the text correctly. MsgBox(My.Computer.Clipboard.GetText( )) Related Framework Entries
See AlsoKeyboard Object |