Results 1 to 4 of 4

Thread: SendKeys to DOS App

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    2
    I've been using SendKeys with Windows apps with no problem. DOS apps aren't compatible with it. If I send any character to a DOS app, all it receives is "\".
    I also tried using SendMessage API, SendMessageNum and SendMesageString with no success (it doesn't send anything at all). Is there a possible way to send a key string to a DOS application?

  2. #2
    Guest
    I don't think DOS App's use the same type of messaging a Windows Apps.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    2
    Is there any possible way to emulate the keyboard? I mean SideWinder Software does that, it lets you use your joystick in DOS apps that don't support it.

    I really need to get this working. Please help

  4. #4
    Addicted Member
    Join Date
    Nov 2000
    Location
    Auckland, NZ
    Posts
    182
    Hi, here is some code from MSDN library. Article Q142819.

    All following is extract from it:
    ------------------
    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.



    Step-by-Step Example
    The following example demonstrates how to send keystrokes to an MS-DOS session running in a window:


    Start an MS-DOS session running in a window.

    Start Visual Basic for Windows and start a new project.

    Enter the following into the general declarations section of the form:


    Dim progname As String


    Put two labels on the form. Change the first label's caption to "MS-DOS App Title." Change the second label's caption to "Keys to send."

    Put two text boxes on the form next to each of the labels. Delete the default contents of these text boxes. These controls are used to allow the user to enter the MS-DOS-based application's window title and the keystrokes to send to it. Change the Name property of these text boxes to "DosTitle" and "DosKeys" respectively.

    Put a command button on the form, and change its caption to "Send keys."

    Add the following code to the Command1 button click event procedure:

    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.



    Run the program.

    Enter the window title of the MS-DOS-based application into the DosTitle text box. The default window title for an MS-DOS session is "MS-DOS Prompt".

    Enter the keystrokes to send into the DosKeys text box (for

    example, DIR).


    Click the Send Keys button. The keystrokes are sent to the

    Clipboard and then pasted into the MS-DOS window.


    To use this technique in a compiled Visual Basic for Windows program, change the progname assignment from "Microsoft Visual Basic" to the executable file name. Also, to see the text being placed onto the Clipboard, open the Windows Clipboard viewer.
    --------------

    Try it, may it will be useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width