如何将键盘输入发送到Windows98中以窗口模式运行的dos应用程序

问题描述 投票:3回答:2

我的问题是关于非常古老的技术。我有一个任务来自动化在Windows 98中以Windows模式运行的旧DOS软件(光谱法)。我提出了两种不同的解决方案,它们都无法使用with DOS application

  1. 第一个解决方案

    • 使DOS应用程序处于活动状态
    • 通过SendInput函数发送输入,如下所示:
    void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::sendKeysViaInput(const std::vector<DWORD>& keys, int keyPause)
    {
        std::vector<DWORD>::const_iterator it;
        INPUT keyBoardInput;
        keyBoardInput.type = INPUT_KEYBOARD;
        keyBoardInput.ki.wScan = 0;
        keyBoardInput.ki.time = 0;
        keyBoardInput.ki.dwExtraInfo = 0;

        for(it = keys.begin(); it != keys.end(); it++)
        {
            keyBoardInput.ki.wVk = (*it);
            keyBoardInput.ki.dwFlags = 0;   // key down
            SendInput(1, &keyBoardInput, sizeof(INPUT));
            Sleep(keyPause);
            keyBoardInput.ki.dwFlags = 2;   // key up
            SendInput(1, &keyBoardInput, sizeof(INPUT));
            Sleep(keyPause);
        }
    }
  1. [通过i8042键盘控制器生成按键:使用D2命令写入键盘缓冲区命令,像这样(KEYBOARD_CMD_REG-0x64,KEYBOARD_DATA_REG-0x60):
    void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::sendKeysViaKeyboardController(const std::vector<BYTE>& scanCodes, int keyPause)
    {
        std::vector<BYTE>::const_iterator it;
        for(it = scanCodes.begin(); it != scanCodes.end(); it++)
        {
            // wait untill buffer is empty
            int status = 0;
            int result = 0;
            do
            {
                status = _inp(0x64);
                // std::cout <<"Keyboard status: "<< status << std::endl;
                Sleep(10);
            }
            while (status & 1);

            // send scan code for key down
            _outp(KEYBOARD_CMD_REG, 0xD2);
            _outp(KEYBOARD_DATA_REG, (*it));
            result = _inp(KEYBOARD_DATA_REG);
            std::cout <<"Keyboard command result for KEY DOWN: "<< result << std::endl;
            // send scan code for key up
            BYTE keyUpCode = (*it) | 128;
            Sleep(keyPause);
            _outp(KEYBOARD_CMD_REG, 0xD2);
            _outp(KEYBOARD_DATA_REG, keyUpCode);
            result = _inp(KEYBOARD_DATA_REG);
            std::cout <<"Keyboard command result for KEY UP: "<< result << std::endl;
        }
    }

我测试了[[这两个解决方案都使用标准的记事本]]窗口(notepad.exe),并且它们都工作正常,但是我无法在DOS应用程序中使用它。 我在其中生成键盘输入(以及整个项目)的代码:https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/saveManager/autoSaveManager.cpp

请您帮我解决这个问题。

我的问题是关于非常古老的技术。我有一个任务可以自动化在Windows 98中以Windows模式运行的旧DOS软件(光谱法)。我做了两个不同的解决方案,它们都具有...

c++ dos keyboard-input windows-98
2个回答
0
投票
首先,我要感谢所有对此帖子感兴趣的人,你们所有人都给了我一些有用的信息,我终于做出了我想要的。

-1
投票
Windows 98中的MS-DOS应用程序以虚拟实模式运行,而不是以保护模式运行,这就是为什么无法使用保护模式驱动程序或系统调用与它们进行通信的原因。您需要使用BIOS / DOS中断与键盘进行交互,Windows驱动程序将无法为您执行此操作。
© www.soinside.com 2019 - 2024. All rights reserved.