简体   繁体   English

如何在所有应用程序中模拟键盘输入?

[英]How to simulate keyboard input in ALL applications?

I'm writing an app (in C#) which as a part of it must simulate and send some key strokes to another application. 我正在编写一个应用程序(在C#中),作为其一部分必须模拟并向其他应用程序发送一些击键。 I'm using http://inputsimulator.codeplex.com/ project for simulating keys, and it works in many applications, but in some it doesn't - ie Mortal Combat 4. 我正在使用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... 我用Google搜索了一下,发现许多答案从“不可能”到“你必须使用XXX库”等等。那些回答让我很害怕,甚至几乎确信我当时无法做到这一点,但...

M$ Virtual Keyboard works. M $虚拟键盘有效。 It works in ALL applications. 它适用于所有应用程序。 So it IS possible... Does anyone of you, clever guys, know how can I achieve this? 所以有可能......你们中有谁聪明的人知道我怎么能做到这一点?

Ok, I think I finally got it to work. 好吧,我想我终于开始工作了。 I used API Monitor recommended by Neal P and it showed just minimal differences between OSK calls and mine. 我使用了Neal P推荐的API Monitor,它显示了OSK调用与我之间的差异很小。 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. 过了一会儿,我试图让我的调用线程在发送带有按键和释放键的消息之间休息一段时间,就是这样。

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 library that can help in this situations, it provides a simple C API that internally communicates with device filter drivers. 我已经构建了一个可以在这种情况下提供帮助的 ,它提供了一个简单的C API,可以在内部与设备过滤器驱动程序通信 It is able to send input for DirectInput based games and also is able to bypass some game protections. 它能够为基于DirectInput的游戏发送输入,并且还能够绕过一些游戏保护。 I have checked and it is still able to bypass some known game protections by using the x64 version of the library. 我已经检查过,它仍然能够通过使用库的x64版本绕过一些已知的游戏保护。 Game protections commonly hook only the x86 system's api. 游戏保护通常只挂钩x86系统的API。 Well, at last now, 18 February 2012, this is what I'm seeing happening. 好吧,最后,现在,2012年2月18日,这就是我所看到的情况。

看看MSDN上的SendKeys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM