键盘模拟不适用于游戏 [英] Keyboard simulation does not work for game

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

问题描述

你好我用c#模拟键盘,这段代码工作正常,并发送命令到IE,记事本,Crome,但它无法发送命令到游戏(我从微软商店下载赛车游戏,并试图发送命令加速汽车使用键盘向上键同样键盘左键和右键分别左右转动汽车但失败。

我从下面的链接中引用了代码。

http://inputsimulator.codeplex.com/ [ ^ ]



我听说过ActiveX控制器,但没有找到详细代码的地方。

我正在使用窗口8和vs2012 express。



提前谢谢

解决方案

我为我找到了解决方案问题。

我从链接下载了InputManagerSendingMessages示例
下载

InputManager库 - 跟踪用户输入并模拟输入(鼠标和键盘) [ ^ ]

并修改了一下给定

  private   void  WriteExampleText_Click(  object  sender,EventArgs e)
{

Thread.Sleep( 10000 );
Keyboard.KeyDown(Keys.Up);
Thread.Sleep( 1000 );
Keyboard.KeyDown(Keys.Left);
Thread.Sleep( 1000 );
Keyboard.KeyDown(Keys.Right);

}
运行代码并启动游戏(现在代码将运行 in 背景),在 10 之后,第二辆车 get 命令。
以上代码为ActiveX游戏提供了完美的命令,例如 Need For Speed Underground
我感谢作者,代码项目和专家回复像我这样的天真程序员。


< blockquote>它不起作用。您为将键盘消息发送到其他应用程序而编写的代码可能正在使用SendKeys。这不适用于大多数游戏DirectX上运行的任何东西。 DirectX直接查看键盘,绕过普通应用程序和SendKeys使用的Windows消息传递功能。



AFAIK,没有办法让DirectX兼容SendKeys,至少在没有编写设备驱动程序的情况下。


Hi I simulated keyboard using c#,this code work fine and send command to IE, Notepad, Crome,but it fail to send command to game (I downloaded car racing game from Microsoft store and tried to send command to speedup the car using keyboard Up key likewise keyboard left key and right key to turn car left and right respectively but failed.
I referred code from following link.
http://inputsimulator.codeplex.com/[^]

I have heard of ActiveX contol but no where I could find its detail code.
I am using window 8 and vs2012 express.

Thanks in advance

解决方案

I found solution for my problem.
I downloaded " InputManagerSendingMessages example" from link
Download
InputManager library - Track user input and simulate input (mouse and keyboard)[^]
and modified a bit as given

private void WriteExampleText_Click(object sender, EventArgs e)
        {
           
            Thread.Sleep(10000); 
            Keyboard.KeyDown(Keys.Up);
            Thread.Sleep(1000);
            Keyboard.KeyDown(Keys.Left);
            Thread.Sleep(1000);
            Keyboard.KeyDown(Keys.Right);

        }
Run this code and start the game(now code will run in the background), after 10 second car will get command. 
 Above code gives perfect command to ActiveX game such as "Need For Speed Underground"
I am thankful to the author, code project and experts replying to  naïve programmer like me.


It won't work. The code you've written to send keyboard messages to other applications is probably using SendKeys. This doesn't work with anything running on DirectX, which is most games. DirectX looks at the keyboard directly, bypassing the Windows messaging functions that normal applications, and SendKeys, uses.

AFAIK, there is no way to make a DirectX compatible equivilent of SendKeys, at least not without writing a device driver.


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

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