SendInput 不适用于游戏
我正在使用以下标准的GenerateKey代码:
void GenerateKey ( int vk , BOOL bExtended)
{
KEYBDINPUT kb={0};
INPUT Input={0};
// generate down
if ( bExtended )
kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
// generate up
::ZeroMemory(&kb,sizeof(KEYBDINPUT));
::ZeroMemory(&Input,sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if ( bExtended )
kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
}
我调用此函数来模拟箭头键(上、下、左、右)。然而,这适用于普通的资源管理器窗口和小型 Flash 游戏。然而,当我在《Need for Speed》或《Roadrash》等游戏上尝试它时,它不起作用。这种行为有什么可能的原因吗?
I am using the following standard GenerateKey Code :
void GenerateKey ( int vk , BOOL bExtended)
{
KEYBDINPUT kb={0};
INPUT Input={0};
// generate down
if ( bExtended )
kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
// generate up
::ZeroMemory(&kb,sizeof(KEYBDINPUT));
::ZeroMemory(&Input,sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if ( bExtended )
kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
}
I call this function to simulate the arrow keys(up, down, left, right). However, this works in the normal explorer window and small flash games. However, when I try it on games like Need for Speed or Roadrash it does not work.. Any possible reasons for this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的游戏很可能使用在较低级别工作的 DirectInput,因此您无法使用 SendInput() 向其注入事件。可能需要键盘过滤器驱动程序才能执行您想要的操作。我快速进行了谷歌搜索,但没有找到任何明确的信息,但我希望这能让您了解需要走哪条路。
应该有一个键盘筛选器驱动程序示例 使用 WDK(Windows 驱动程序工具包),您可以根据自己的目的进行修改。这会很复杂。
Your games most likely use DirectInput which works at a lower level so you can not inject events to it using SendInput(). A keyboard filter driver may be required to do what you want. I did quick Googling but didn't come up with anything definite but I hope this gives you some idea of which way you need to go.
There should be a keyboard filter driver sample with the WDK (Windows Driver Kit) that you could modify for your purposes. It would be pretty involved.