windows 如何在所有应用程序中模拟键盘输入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8760397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to simulate keyboard input in ALL applications?
提问by Fenix Voltres
I'm writing an app (in C#) which as a part of it must simulate and send some key strokes to another application. I'm using http://inputsimulator.codeplex.com/project for simulating keys, and it works in many applications, but in some it doesn't - i.e. Mortal Combat 4.
我正在编写一个应用程序(在 C# 中),作为它的一部分,它必须模拟并将一些击键发送到另一个应用程序。我正在使用http://inputsimulator.codeplex.com/项目来模拟键,它适用于许多应用程序,但在某些应用程序中却没有 - 即 Mortal Combat 4。
I've googled about it, and found many answers varying from 'it's impossible' to 'you must use XXX library' etc. Those answered scared me a lot, and even nearly convinced I'm not able to do it at that time, BUT...
我用谷歌搜索了一下,发现了很多答案,从“不可能”到“你必须使用 XXX 库”等等。这些答案让我很害怕,甚至几乎确信我当时做不到,但...
M$ Virtual Keyboard works. It works in ALL applications. So it IS possible... Does anyone of you, clever guys, know how can I achieve this?
M$ 虚拟键盘有效。它适用于所有应用程序。所以这是可能的......你们中的任何人,聪明的人,知道我怎样才能做到这一点吗?
采纳答案by Fenix Voltres
Ok, I think I finally got it to work. I used API Monitor recommended by Neal Pand it showed just minimal differences between OSK calls and mine. A bit later I've tried to make my calling thread sleep some time between sending messages with press and release key and that was it.
好的,我想我终于让它工作了。我使用了Neal P推荐的 API Monitor ,它显示 OSK 调用和我的调用之间的差异很小。稍后,我尝试让我的调用线程在使用按下和释放键发送消息之间休眠一段时间,仅此而已。
回答by pepper_chico
Although you were able to achieve your purpose, the way you achieved it does not fundamentally answer your question: How to simulate keyboard input in ALL applications?
尽管您能够实现您的目的,但您实现它的方式并没有从根本上回答您的问题:如何在所有应用程序中模拟键盘输入?
There's a bunch of situations where the common user mode Microsoft API already mentioned does not work, like game applications that use the DirectInput API or protected games.
已经提到的通用用户模式 Microsoft API 在许多情况下不起作用,例如使用 DirectInput API 的游戏应用程序或受保护的游戏。
I have built a librarythat can help in this situations, it provides a simple C API that internally communicates with device filter drivers. It is able to send input for DirectInput based games and also is able to bypass some game protections. I have checked and it is still able to bypass some known game protections by using the x64 version of the library. Game protections commonly hook only the x86 system's api. Well, at last now, 18 February 2012, this is what I'm seeing happening.
我构建了一个可以在这种情况下提供帮助的库,它提供了一个简单的 C API,可以在内部与设备过滤器驱动程序进行通信。它能够为基于 DirectInput 的游戏发送输入,也能够绕过一些游戏保护。我已经检查过,它仍然能够通过使用该库的 x64 版本绕过一些已知的游戏保护。游戏保护通常只挂钩 x86 系统的 api。好吧,终于在 2012 年 2 月 18 日,这就是我所看到的。