?
Solved

How do I send keystrokes to a Matlab.exe

Posted on 2007-08-03
1
Medium Priority
?
1,091 Views
Last Modified: 2016-02-10
I have a microsoft Access database that contains information used to update a configuration file that is read by a Matlab executable.  What I would like to do is use visual basic to create the config file, then launch the .exe.  In order for the .exe to complete, I need to type in "y" and then "enter".  I have been able to get as far as creating the config file and launching the .exe.  However when I try to send keystrokes, the keystrokes do not appear in the window that is opened when the .exe is launched.  Below is the code I have so far.  Any help would be greatly appreciated.

Dim Filepath As String
Dim ConfigFile As String
Dim lngReturn As Long
Dim MatlabFile As String
Dim OutputFile As String
Dim RunTask As Long

Filepath = BrowseFolder("Select Folder to drop off Config Files")
ConfigFile = Filepath & "\matlab\config.txt"
MatlabFile = Filepath & "\matlab\matlabfile.exe"

Open ConfigFile For Output As #1
    Print #1, "Sometext here"
    Close #1

ChDir (Filepath & "\matlab")
RunTask = Shell(MatlabFile, 1)

AppActivate RunTask

SendKeys "y", True
SendKeys "{ENTER}", True

Kill ConfigFile

End Function
0
Comment
Question by:Giocatrice
1 Comment
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 1500 total points
ID: 19627689

you should add a little delay before sending the keystrokes,
500 ms should be enough, depending on the program/pc speed
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question