如何在 C# 中接收非托管 Win32 和 Win64 应用程序的 Windows 消息?
我在 Windows 7 64 上有一个 32 位和 64 位的非托管应用程序。
我想编写一个 C# 应用程序来接收它正在接收的键盘消息,这样我就可以在按下某些按键时执行某些操作,而对于其他按键,只需发送它即可返回应用程序,以免干扰他们。
我不知道搜索这个的正确方法,所以不确定如何做到这一点。
另外,如果可能的话,我想避免使用键盘挂钩。我只想接收应用程序的键盘消息。
I have an unmanaged app both in 32 bit and 64 bit on Windows 7 64.
I want to write a C# application to receive the keyboard messages it's receiving, so I could do certain things on certain key presses, and for others, simply send it back to the app, so as not to interfere with them.
I don't know the right way to search for this so not sure how this would be done.
Also I want to avoid using keyboard hooks if possible. Just want to receive the app's keyboard messages is what I am trying to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是键盘挂钩的设计目的。没有任何替代方案可以解决键盘挂钩的所有问题(可能还有一些其他问题)。
That's what keyboard hooks are designed for. There aren't any alternatives that don't have all the problems of keyboard hooks (and probably some additional ones).
有关向特定窗口添加挂钩的信息,请参阅此处。我不知道如何读取其他应用程序的消息泵。您可以使用 IMessageFilter 来完成此操作,但它仅适用于当前应用程序...
See here about adding hooks to specific windows. I've no idea how to read the message pump of other apps. You can do it with a IMessageFilter but it only will work in the current app...