Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C虚拟键盘输入选择性工作_C++_C_Visual Studio 2010_Keyboard Events_Virtual Keyboard - Fatal编程技术网

C++ C虚拟键盘输入选择性工作

C++ C虚拟键盘输入选择性工作,c++,c,visual-studio-2010,keyboard-events,virtual-keyboard,C++,C,Visual Studio 2010,Keyboard Events,Virtual Keyboard,我正在从事一个需要虚拟输入的项目,该项目正在Microsoft Visual Studio中使用windows.h标题进行编码。为此,我使用keybd_事件方法和VkKeyScan方法: keybd_event(VkKeyScan('w'), 0, 0, 0); keybd_event(VkKeyScan('w'), 0, KEYEVENTF_KEYUP, 0); 但是,虚拟输入只能被某些程序识别,例如记事本、命令提示符、浏览器和其他使用文本字段的应用程序。我的项目使用虚拟输入的目的是使用客户

我正在从事一个需要虚拟输入的项目,该项目正在Microsoft Visual Studio中使用windows.h标题进行编码。为此,我使用keybd_事件方法和VkKeyScan方法:

keybd_event(VkKeyScan('w'), 0, 0, 0);
keybd_event(VkKeyScan('w'), 0, KEYEVENTF_KEYUP, 0);
但是,虚拟输入只能被某些程序识别,例如记事本、命令提示符、浏览器和其他使用文本字段的应用程序。我的项目使用虚拟输入的目的是使用客户端控制VisualGameBoyAdvance,它接受键盘输入,然后将键盘输入转换为命令,如“w”=开始,“z”=按钮等

为什么在文本字段中使用应用程序时读取虚拟输入,而不是作为命令?是否有windows.h头文件的替代方法,或者在头文件中是否有更好的方法

更新:我一直在尝试使用VkKeyScanEx作为一种替代方法,将虚拟输入作为黑暗中的一个镜头。如何指定输入区域设置标识符?我一直在尝试使用UTF-8和en_AU.UTF-8,但运气不好。是否有一个图表可以解释如何指定这一点

我也试过使用

keybd_event(GetKeyState('w'), 0, 0, 0);
keybd_event(GetKeyState('w'), 0, KEYEVENTF_KEYUP, 0);
这根本不起作用,我试过了

while(1){
        /*Sleep(1000);
        keybd_event(GetKeyState('w'), 0, 0, 0);
        keybd_event(GetKeyState('w'), 0, KEYEVENTF_KEYUP, 0);*/
        // Pause for 5 seconds.
    Sleep(500);

    // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;

    // Press the "W" key
    ip.ki.wVk = 0x57; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));

    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));

    // Exit normally
    }

问题是游戏是通过DirectX运行的,这阻止了虚拟键盘的敲击。通过将游戏从sys中分离出来,它完全避免了directx,并且运行良好: