SendInput不适用于游戏 [英] SendInput Not working for Games

查看:799
本文介绍了SendInput不适用于游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下标准的GenerateKey代码:

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));
}

我将此功能称为模拟箭头键(上,下,左,右).但是,这可以在常规资源管理器窗口和小型Flash游戏中使用.但是,当我在《极品飞车》或《 Roadrash》等游戏中尝试使用该游戏时,此方法无法正常工作.

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?

推荐答案

您的游戏最有可能使用DirectInput,后者在较低级别上起作用,因此您无法使用SendInput()向其注入事件.可能需要键盘过滤器驱动程序来执行您想要的操作.我进行了快速谷歌搜索,但没有提出明确的建议,但是我希望这可以使您对需要采取的方式有所了解.

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.

应该有一个键盘过滤器驱动程序示例与WDK(Windows驱动程序工具包)一起使用,您可以针对自己的目的对其进行修改.会很累的.

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.

这篇关于SendInput不适用于游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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