全局键盘挂钩 (C#)
Possible Duplicate:
Global keyboard capture in C# application
Can anyone help me setup a global keyboard hook for my application?
I want to set hotkeys (such as Ctrl+S) that can be used when not focused on the actual form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Paul 的帖子链接到两个答案,一个告诉您如何实现挂钩,另一个告诉您调用 RegisterHotKey。 您不需要为像 Ctrl+S 热键这样简单的东西安装挂钩,因此调用 RegisterHotKey 相反。
Paul's post links to two answers, one telling you how to implement a hook, and another telling you to call RegisterHotKey. You shouldn't need to install a hook for something as simple as a Ctrl+S hotkey, so call RegisterHotKey instead.
或者您可以使用 C# 的 MessageFilter。 当应用程序进程中的任何控件/表单具有焦点时,它应该可以工作。
示例代码:
不仅仅是向您的应用程序添加一个新的 MessageFilter:
Or you can use C#'s MessageFilter. It should work while any control/form from your application's process has focus.
Sample Code:
And than simply add a new MessageFilter to your Application: