如何创建非窗口边界的键盘快捷键 [英] how to create non window bound keyboard shortcuts

查看:140
本文介绍了如何创建非窗口边界的键盘快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个C#应用程序,可能是WinForm的,但最好的控制台应用程序,这需要捕捉键盘快捷键,即使该应用程序是不是在前台。如何将一个做到这一点,我知道这是可能的,即鸣禽可以做到这一点。

I'm creating a C# application, could be WinForm, but preferably console application, which needs to capture keyboard shortcuts even when the application is not in the foreground. How would one do this, I know this is possible as i.e. Songbird can do this.

这键盘快捷键将是形式<大骨节病> CTRL + <大骨节病>的 - >
我至今别吨有任何代码,因为我甚至不就如何在全球范围内注册的键盘快捷键丝毫的想法。

This keyboard shortcuts would be of the form ctrl+-> I so far don't have any code as I don't even have the slightest idea on how to register keyboard shortcuts globally.

推荐答案

您应该使用 RegisterHotkey 并没有一个键盘钩子。

You should use RegisterHotkey and not a keyboard hook.

使用全局键盘钩子,当你只想要一个全局热键是API的滥用。它也有负面的性能影响,因为每个键需要你的程序来处理它到达目标程序之前。

Using a global keyboard hook when you just want a global hotkey is an abuse of the api. It also has negative performance implications since every key needs to be processed by your program before it arrives at the target program.

这篇关于如何创建非窗口边界的键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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