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
    Posts
    1

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

    Hello,

    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:

    Code:
    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

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

    Code:
     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
    Location
    Chicago, IL
    Posts
    64
    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.

    http://www.codeguru.com/vb/gen/vb_sy...le.php/c14629/
    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, 11:17 AM
  2. VB Winsock Help, IM Program Help Will Pay
    By anonyentry in forum VB Classic
    Replies: 0
    Last Post: 05-27-2006, 03:06 AM
  3. Calling A Windows Batch Program From VB
    By J. Long in forum VB Classic
    Replies: 1
    Last Post: 03-20-2002, 09:12 AM
  4. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 11:06 AM
  5. The day that everything went wrong!!!
    By WHYVB? in forum .NET
    Replies: 0
    Last Post: 10-03-2001, 10: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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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