将键盘事件发送到不处理Windows事件的C#中的另一个应用程序 [英] Sending keyboard events to another application in C# that does not handle Windows events

查看:67
本文介绍了将键盘事件发送到不处理Windows事件的C#中的另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:我们正在编写一个必须将Microsoft Kinect坐标转换为键盘和鼠标事件的应用程序.

here is my situation: we are writing an application that must transform Microsoft Kinect coordinates into keyboard and mouse events.

当我们需要控制鼠标时,一切都可以在任何类型的应用程序中正常运行.例如,当我们需要将键盘事件(例如按下或按下键盘)发送到不处理Windows事件的应用程序(例如游戏)时,就会出现问题.

When we need to take control of the mouse, everything works as we intended in ANY kind of application. The problem arises when we need to send keyboard events (like key down or key up) to applications that doesn't handle Windows events, like games, for example.

我们尝试了.net框架的SendKeys类,它仅适用于Windows应用程序.当应用程序是《半条命》或《毁灭战士》之类的游戏时,我们将无法获得相同的效果.因此,这是我的问题:我们如何才能有效地将键盘事件发送到其他应用程序?

We tried the SendKeys class of the .net framework, and it only works with Windows applications. When the application is a game like Half-Life or Doom we can't get the same effect. So, here is my question: how can we effectively send keyboard events to these other applications?

推荐答案

您需要使用

You need to simulate input using SendInput. SendMessage and SendKeys tend to work at the level of windows messages - but DirectX apps don't run a traditional message loop.

PInvoke.NET 上有一个页面,但是我不得不承认,我尚未尝试使用它.

There is a page on PInvoke.NET, but I have to confess, I've not tried to use it.

另请参见此线程在GameDev.net网站上,那里有人处理过一些磨牙"问题,这些问题尤其是在与基于DirectInput的应用程序进行交互时遇到的.

See also this thread on the GameDev.net site, where someone has worked with some of the "teething" issues that can be encountered specifically interacting with a DirectInput based application.

这篇关于将键盘事件发送到不处理Windows事件的C#中的另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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