How do I send keystrokes to a Matlab.exe

Posted on 2007-08-03
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
Question by:Giocatrice
    1 Comment
    LVL 13

    Accepted Solution


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

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now