michisoft.com

Send keys/commands to other applications

It is easy to send keys or phrases to an application using Visual Basic. For this example, create a new project and create a command button. Start WordPad and go back to VB. Insert all of the code into the click() event of the command button. We now want to send some keys or a phrase to WordPad. All there is to do is to activate the wordpad window:

---code begins here---

AppActivate "WordPad"

---code ends here---

And then just send the phrase:

---code begins here---

SendKeys "This is a test."

---code ends here---

You can also send commands and special keys:

---code begins here---

SendKeys "%{F4}"

---code ends here---

This command sends the "Alt + F4" command and Wordpad. Wordpad will then ask if you would like to save. Now just send the "n" key:

---code begins here---

SendKeys "n"

---code ends here---

The Visual Basic help describes in detail how to use theese two commands and contains a listing of codes for special keys like "{BACKSPACE} {BREAK} {ENTER}".

Go back to my vb-page.