C# 全局热键(不带常用的全局钩子)
我正在创建一个供我个人使用的程序,它必须对某些热键做出反应。例如,当我按 ctrl+win+z 时,它必须执行某个操作。目前,我可以使用 user32.dll 中的 GetKeyState() 来检测按键,但是我无法阻止它们传递到活动应用程序。在 ctrl+win+z 的情况下,我想要发生的操作发生,但如果我使用资源管理器,例如,资源管理器也会将其读取为“撤消”。
明显的解决方案是使用“SetWindowsHookEx()”(也来自 user32.dll),但是每次我尝试涉及它的解决方案时(任何类似于 此网站的 示例代码)第一次使用热键时,速度大幅减慢。这是不可接受的。
我希望有人能提供帮助。如果需要,我可以提供更多信息。
I'm creating a program for my personal use that must react to some hotkeys. For example, when I press ctrl+win+z it must perform a certain action. At present, I can use GetKeyState() from user32.dll to detect the keypresses, however I am unable to stop them being passed to the active application. In the case of ctrl+win+z, the action I want to happen occurs, but if I am using explorer, for example, explorer will also read that as an 'undo'.
The obvious solution would be to use "SetWindowsHookEx()" (also from user32.dll), however each time I try a solution involving it (anything similar to this site's example code) I get a massive slow down the first time I use the hotkey. This is not acceptable.
I hope someone can help. I can provide more information if required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过RegisterHotKey功能?它绝对比 windows hook 更容易使用。
Have you tried the RegisterHotKey function? It's definitely easier to use than a windows hook.