Using VB to send keyboard input to an MS-DOS program

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Using VB to send keyboard input to an MS-DOS program

  1. #1
    Join Date
    May 2008

    Using VB to send keyboard input to an MS-DOS program


    I am on Windows XP, and I am trying to use VB scripts to send keyboard input to an MS-DOS program. The problem is that through some weird bug in the MS-DOS program, it is only able to accept a character every 500 ms. It has no interface for automation, so I am trying to get Windows to send keys to the program for me.

    Here is an example of a script that successfully sends input into internet explorer:

    Set shell = WScript.CreateObject ("WScript.Shell")
    appName = "iexplore.exe"
    Sub giveItAKeystroke (keystrokes, name)
    	shell.AppActivate name
    	shell.SendKeys keystrokes
    End Sub
    WScript.Sleep 500
    shell.Run appName
    WScript.Sleep 3000
    Call giveItAKeystroke ("Hello World!", appName)
    This technique pretty much works for any applications EXCEPT MS-DOS. How does one send input to an MS-DOS program? I've searched the web, but I have found few satisfying answers. One way is to send it input from a text file by calling a batch file That is, my script would include something like

     shell.Run "supporting.bat"
    and then the batch file would have

     msDosProg.exe < textFileWithInput.txt
    The problem with this is that it feeds in everything in the text file at once, and my program only accepts one character every 0.5 seconds.

    I could have a text file for every character, but this won't work because doing msDosProg.exe < textFileWithInput.txt starts a new instance of msDosProg.exe, and I need all the input to be put into a single instance.

  2. #2
    Join Date
    May 2008
    Chicago, IL
    Using API's you might be able to do it. Check out this article that I reviewed. I've used it to send keys to a Java program. I had a 50ms timer between keys. Oddly enough, I needed a VB.Tab to click the submit button.
    David CodeGuru Article: Bound Controls are Evil-VB6

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Similar Threads

  1. Net Send Program
    By Dude in forum VB Classic
    Replies: 0
    Last Post: 10-19-2006, 10:17 AM
  2. VB Winsock Help, IM Program Help Will Pay
    By anonyentry in forum VB Classic
    Replies: 0
    Last Post: 05-27-2006, 02:06 AM
  3. Calling A Windows Batch Program From VB
    By J. Long in forum VB Classic
    Replies: 1
    Last Post: 03-20-2002, 08:12 AM
  4. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM
  5. The day that everything went wrong!!!
    By WHYVB? in forum .NET
    Replies: 0
    Last Post: 10-03-2001, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center