How Do I make Visual basic click on other icons in other programs. Like The next and finish and Install cmd buttons. Is it possible to copy text out of a text out of text boxes and Enter them into a program. Kinda Like COPY AND PASTE

Recommended Answers

All 5 Replies

You'll want to look into the "sendkeys" command. This command allows you to send keystrokes to applications (shift-end, ctrl-c, ctrl-v). Keep in mind, sendkeys only sends keystrokes to the currently active (foreground) window. So, you'll want to make whatever window you want to mess with the foreground first, with either appactivate, or the setforegroundwindow (and setactivewindow) api calls. If you want to get more complicated than that (say, cross-task subclassing) you are going to want to be very... very careful.

You'll want to look into the "sendkeys" command. This command allows you to send keystrokes to applications (shift-end, ctrl-c, ctrl-v). Keep in mind, sendkeys only sends keystrokes to the currently active (foreground) window. So, you'll want to make whatever window you want to mess with the foreground first, with either appactivate, or the setforegroundwindow (and setactivewindow) api calls. If you want to get more complicated than that (say, cross-task subclassing) you are going to want to be very... very careful.

How would i use the send keys in my program

Sendkeys is usually not a great idea.... because there are a ton of problems that can occur. What if the user switches focus (or what if there is spyware or some other junk that spawns new windows for the hell of it), while your program is in the midst of sending keys..... all hell can break loose. Read up on this thread, and check out this page: http://www.daniweb.com/techtalkforums/post127770.html
http://www.scriptlogic.com/Kixtart/htmlhelp/Functions/sendkeys.htm

Private Sub Form_Load()
Shell "c:\windows\notepad.exe", vbNormalFocus
Me.Show
AppActivate "Untitled - Notepad"
SendKeys "This Is A Test!"
SendKeys "+{HOME}"
End Sub

Sendkeys is usually not a great idea.... because there are a ton of problems that can occur. What if the user switches focus (or what if there is spyware or some other junk that spawns new windows for the hell of it), while your program is in the midst of sending keys..... all hell can break loose. Read up on this thread, and check out this page: http://www.daniweb.com/techtalkforums/post127770.html
http://www.scriptlogic.com/Kixtart/htmlhelp/Functions/sendkeys.htm

Private Sub Form_Load()
Shell "c:\windows\notepad.exe", vbNormalFocus
Me.Show
AppActivate "Untitled - Notepad"
SendKeys "This Is A Test!"
SendKeys "+{HOME}"
End Sub

If Send Keys are a bad idea, what you you do to click on the buttons that need to be clicked in this program.

Well, generally it's a poor idea to try to automate a program that isn't made to be automated. Excel for example, let's you create an object in it's name, and work with it's properties and methods. Trying to force yourself on a program that doesn't expect it, can lead to crappy results. That's all I'm saying.... sendkeys may well be your only option, unless you dig into something like findwindow, and findwindowEX api calls, and then use the sendmessage API.... but findwindow and findwindowex can produce some flakey results when trying to find a specific child window...... stick with sendkeys, but just know that what you are doing is Taboo.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.