使用直接输入向游戏发送按键 [英] Send Key Strokes to Games using Direct Input

查看:132
本文介绍了使用直接输入向游戏发送按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 PostMessage api发送任何Windows应用程序按键。但是我不能通过使用 PostMessage 将击键发送到游戏窗口。

I can send any windows application key strokes with PostMessage api. But I can't send key strokes to Game window by using PostMessage.

任何人都知道使用直接输入的知识从C#向游戏发送键的函数。

Anyone know anything about using Direct Input functions for sending keys to games from C#.

推荐答案

另一种方法是直接挂接DirectInput API-Microsoft Research提供了一个已经可以做到这一点的库: http://research.microsoft.com/zh-CN / projects / detours /

An alternate way would be to hook the DirectInput API directly - Microsoft Research has provided a library to do this already: http://research.microsoft.com/en-us/projects/detours/

一旦挂接到API,就可以使用它进行任何操作。但是,值得注意的是,在Windows的最新版本中,DirectInput for mouse&键盘输入只是Win32 Windows消息的包装。 DirectInput在后台生成线程,并在将窗口消息传递回应用程序之前仅拦截窗口消息。这是Microsoft不再建议使用DirectInput的原因之一-这意味着诸如PostMessage 之类的消息传递API可以正常工作。

Once you hook into the API, you can do whatever you want with it. However, it's worth noting that in recent versions of Windows, DirectInput for mouse & keyboard input is just a wrapper around the Win32 windows messages. DirectInput spawns a thread in the background and simply intercepts window messages before passing them along back to the application. It's one of the reasons why Microsoft no longer recommends the use of DirectInput - and it means that messaging APIs like PostMessage should work just fine.

这篇关于使用直接输入向游戏发送按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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