如何将键盘输入发送到Windows98中以窗口模式运行的Dos应用程序 [英] How to send keyboard input to dos application running in window mode in Windows98

查看:100
本文介绍了如何将键盘输入发送到Windows98中以窗口模式运行的Dos应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于非常古老的技术。我有一个任务可以自动化在Windows 98中以Windows模式运行的旧DOS软件(光谱)。我提出了两种不同的解决方案,它们都不能在DOS应用程序中正常运行。 strong>:

My question is about very antique techologies. I have a task to automate old DOS software (spectrometric) that is running in Windows mode in Windows 98. I made two different solution hovewer both of them doesn't work with DOS application:


  1. 第一个解决方案

  1. First Solution


  • 使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应用程序中使用它。

I tested both of these solutions with standard Notepad window (notepad.exe) and both of them works fine, but i can't get it work with DOS application.

我在其中生成键盘输入(以及整个项目)的代码: https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/saveManager/autoSaveManager。 / a>

My Code where i generate keyboard input (and whole project): https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/saveManager/autoSaveManager.cpp

请帮助我解决此问题。

推荐答案

首先,我要感谢所有对此帖子感兴趣的人,所有人都给了我一些有用的信息,我终于做到了我想要的。

First of all i want to thank all who interesting this post, all of you gave me some useful info and i finally made what i wanted.

关于其实现方式:我已经创建了VXD驱动程序(这是我的专有驱动程序,由于我计划将其用于以下用途,因此无法在此处发布代码)商业项目)。但是,此注释的主要目标- 是,可以为在Windows 98中以窗口模式运行的DOS应用程序模拟键盘输入 。我可以发布的部分解决方案位于github上: https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/saveManager/autoSaveManager.cpp

About how it was implemented: i've created VXD driver (it is my proprietary driver and i can't post it code here because i am planning to use it for commercial projects). But the main goal of this comment - YES, it is possible to simulate KEYBOARD INPUT for DOS application running in Windows 98 in window mode. Part of my solution that i could post is on github: https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/saveManager/autoSaveManager.cpp

这里我正在使用vXd访问器类:( https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/utils/windows/vxdAccessor.cpp

Here i am using vXd accessor class: (https://github.com/MossbauerLab/Sm2201Autosave/blob/master/MossbauerLab.Sm2201.ExtSaveUtility/src/utils/windows/vxdAccessor.cpp)

主要思想-使用W32_DEVICEIOCONTROL驱动程序消息处理程序和DeviceIoControl函数与驱动程序进行交互,并使用CTL(在驱动程序中定义)传递具有1个字节对齐的结构。代码:我未使用CTL_CODE宏。这个Github项目几乎已准备就绪〜95%(目前,我只需要手动选择窗口以通过单击鼠标激活它并检查是否有适当的内存来发送即可。)

Main idea - interact with driver using W32_DEVICEIOCONTROL driver message handler and DeviceIoControl function and passing struct that have 1 byte align using CTL (define in my driver) CODES: i did not used CTL_CODE macro. This Github project is almost ready ~95% (at present time i just have to manual select window to send by activate it with mouse click and check proper memory free).

这篇关于如何将键盘输入发送到Windows98中以窗口模式运行的Dos应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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