将击键发送到包裹在NTVDM中的16位DOS应用程序 [英] Sending a keystroke to a 16bit DOS application wrapped in NTVDM

查看:101
本文介绍了将击键发送到包裹在NTVDM中的16位DOS应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将击键发送到包含在NTVDM中的16位DOS应用程序。我下面的代码目前能够成功地向任何应用程序(例如记事本)发送击键,包括命令提示符,这让我想知道为什么它不能与我试图发送的DOS应用程序一起工作。虽然我认为它与在NTVDM中包装的DOS应用程序有关。希望有人能给我一些线索。我的代码成功找到了正确的应用程序并将其带到前台但它没有响应我发送给它的任何按键:



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

}

推荐答案

使用剪贴板(System.Windows.Forms.Clipboard)可能会更好。请参阅 http://msdn.microsoft.com /en-us/library/system.windows.forms.clipboard(v=vs.110).aspx [ ^ ]
You may have better luck with the Clipboard (System.Windows.Forms.Clipboard). Please see http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard(v=vs.110).aspx[^]


SA,请得到一个生活。我一直在谈论在NTVDM中运行的应用程序多年。这并不容易,但我在剪贴板上取得的成功比试图强制进行击键更多。
SA, please get a life. I've been talking to applications running in NTVDMs for years. it's not easy, but I've had much more success with the clipboard than with trying to force feed keystrokes to it.


这篇关于将击键发送到包裹在NTVDM中的16位DOS应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆