CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2014
    Posts
    2

    Sending a keystroke to a 16bit DOS application wrapped in NTVDM

    I am trying to send keystrokes to a 16bit DOS application that is wrapped in NTVDM. My code below currently is able to successfully send keystrokes to any application (e.g. Notepad) including the command prompt which makes me wonder why it doesnt work with the DOS application im trying to send to. Though i believe it has something to do with the DOS application being wrapped in NTVDM. Hopefully somebody can give me some clues. My code successfully finds the correct application and brings it to the foreground but it doesn't respond to any keystrokes I send to it:

    [DllImport("user32.dll")]
    static extern uint MapVirtualKey(uint uCode, uint uMapType);


    [DllImport("user32.dll")]
    static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);

    const uint KEYEVENTF_KEYUP = 0x0002;
    const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
    const int VK_UP = 0x26; //up key
    const int VK_DOWN = 0x28; //down key
    const int VK_LEFT = 0x25;
    const int VK_RIGHT = 0x27;
    const int VK_NUMPAD0 = 0x60;
    const int VK_NUMPAD1 = 0x61;
    const int VK_NUMPAD2 = 0x62;
    const int VK_NUMPAD3 = 0x63;
    const int VK_NUMPAD4 = 0x64;
    const int VK_NUMPAD5 = 0x65;
    const int VK_NUMPAD6 = 0x66;
    const int VK_NUMPAD7 = 0x67;
    const int VK_NUMPAD8 = 0x68;
    const int VK_NUMPAD9 = 0x69;
    const int VK_LMENU = 0x12;
    const int VK_SPACE = 0x20;

    private void btnCMD_Click(object sender, EventArgs e)
    {
    Application_Methods.GoToCMD();
    Thread.Sleep(1000);
    byte LMENU = 0x12;
    byte SPACE = 0x20;
    uint scanCode = MapVirtualKey((uint)LMENU, 0);
    uint scanCode1 = MapVirtualKey((uint)SPACE, 0);
    keybd_event(LMENU, (byte)scanCode, 0, 0);
    keybd_event(SPACE, (byte)scanCode1, 0, 0);
    keybd_event(SPACE, (byte)scanCode1, KEYEVENTF_KEYUP, 0);
    keybd_event(LMENU, (byte)scanCode, KEYEVENTF_KEYUP, 0);
    SendKeys.Send("e");
    SendKeys.Send("s");
    }

    public static void GoToCMD()
    {
    //Find the window, using the CORRECT Window Title
    int hWnd = FindWindow("ConsoleWindowClass", "C:\\Windows\\system32\\cmd.exe");
    ShowWindowAsync(hWnd, SW_SHOWNORMAL);
    SetForegroundWindow(hWnd); //Activate it

    }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Sending a keystroke to a 16bit DOS application wrapped in NTVDM

    I don't think it's about the 16-bit NTVDM, but more likely it's because you are trying to send keystrokes to the command window. Try your program against a 32-bit command window..

  3. #3
    Join Date
    May 2014
    Posts
    2

    Re: Sending a keystroke to a 16bit DOS application wrapped in NTVDM

    Quote Originally Posted by Arjay View Post
    I don't think it's about the 16-bit NTVDM, but more likely it's because you are trying to send keystrokes to the command window. Try your program against a 32-bit command window..
    It works perfectly fine with the windows command prompt. I need it to work with an application that is in 16bit DOS through NTVDM. im not sure what else i can try. I have tried SentInput, keybd_event, Sendkeys etc they all work fine with every application except for the DOS application i need it to work with

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Sending a keystroke to a 16bit DOS application wrapped in NTVDM


Tags for this Thread

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

Featured