• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1117
  • Last Modified:

How do I send keystrokes to a Matlab.exe

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
Giocatrice
Asked:
Giocatrice
1 Solution
 
Mark_FreeSoftwareCommented:

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now