HOWTO: Send Keystrokes from VB App to MS-DOS AppID: Q142819
|
This article demonstrates a technique you can use to send keystrokes to a Microsoft MS-DOS-based application from a Microsoft Visual Basic application running on Microsoft Windows 3.x, Microsoft Windows 95, or Windows 98. This method does not work with Microsoft Windows NT.
The Visual Basic for Windows SendKeys function can send keystrokes to the
currently active window as if the keystrokes had been typed at the
keyboard. Although it is not possible to send keystrokes to an
application that is not based on Windows by using SendKeys directly, you
can place text on the Clipboard and use the SendKeys function to paste that
text into an MS-DOS-based application that is running in a window or
minimized as an icon.
To run an MS-DOS-based application in a window, you must be running in
Windows 386 enhanced mode. You must also make sure that the MS-DOS-based
application's .PIF file has been set to display the application in a window
rather than full screen. Use the Windows PIF Editor to make this
modification, if necessary.
Dim progname As String
Private Sub Command1_Click()
'Ensure that progname is set to the titlebar of Visual Basic while
' running.
progname = "Project1 - Microsoft Visual Basic [run]"
clipboard.Clear
clipboard.SetText DosKeys.Text + Chr$(13) ' Append a <CR>.
AppActivate DosTitle.Text
SendKeys "% ep", 1
AppActivate progname
End Sub
If the text that you send is the DIR command or another command that
takes time, the AppActivate call immediately following the SendKeys
call can interrupt the processing. The AppActivate call should be
placed in a timer with the appropriate interval set, and the timer
should be enabled in the command_click procedure. The timer should
be disabled before exiting the timer.
Additional query words: kbVBp300 kbVBp400 kbVBp kbCtrl kbDSupport kbdsd
Keywords :
Version : 4.00
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: June 9, 1999