GlobalKeyboardHook还是RegisterHotKey? [英] GlobalKeyboardHook Or RegisterHotKey?

查看:59
本文介绍了GlobalKeyboardHook还是RegisterHotKey?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 按下字母A然后它会显示★(Unicode编号

U + 2605),

- 按下字母Ctrl+在任何有针对性的文本编辑器/窗口上,然后它将显示((Unicode编号

U + 262F)。



应该RegisterHotKey支持这个问题?或者我需要查看Global Keyboard HOOK?

- Pressing the letter "A" then it will shows "★" (Unicode number
U+2605),
- Pressing the letter "Ctrl" + "A" then it will shows "☯" (Unicode number
U+262F), on any focused text editors/windows.

Should RegisterHotKey support this problem? or I need to check with Global Keyboard HOOK?

推荐答案

答案很简单,取决于它。这两个问题确实没什么意义。



你没有在这个上下文中定义复杂性,但是如果你询问实现难度,那么Global windows hooks就是其中之一Windows特定编程中最困难的部分,首先是因为调试非常棘手。事实上,仅仅C#应用程序是不够的,因为Microsoft文档声明应该在本机DLL中安装全局钩子(与每个线程相比)。



与此相反,全局挂钩非常简单。即使对于.NET,一切都已经为您完成:

http://www.pinvoke .net / default.aspx / user32.registerhotkey [ ^ ],

http://www.pinvoke.net/default .aspx / user32.unregisterhotkey [ ^ ]。



现在(深呼吸),关于显示ल而不是A的问题,哪种方式更好。答案是:几乎没有你提到的任何方式。并且它与聚焦输入控制无关:在全局系统级别,不可能识别它是什么,因此它应该适用于任何控制,这些控制非常不同,并且通常没有任何共同点。 />


如果您只想输入不同语言的文本,有一个文明的解决方案:创建和注册Windows键盘布局。我在过去的回答中详细解释了这一点:输入印地语和英语的问题 [ ^ ]。



-SA
The answer is simple it depends. Both questions really make little to no sense.

You did not define "complexity" in this context, but if you asking about implementation difficulty, Global windows hooks is one of the most difficult parts of Windows-specific programming, first of all because it's quite tricky to debug. As a matter of fact, just C# application cannot be enough, as Microsoft documentation states that a global hook (in contrast to a per-thread one) should be installed in a native DLL.

In contrast to that, global hooks are quite easy. Even for .NET everything is already done for you:
http://www.pinvoke.net/default.aspx/user32.registerhotkey[^],
http://www.pinvoke.net/default.aspx/user32.unregisterhotkey[^].

And now (deep breath), on your question about showing "ल" instead of 'A', which way is better. The answer would be: hardly any of the ways you mentioned. And it cannot be related to focused input control: on the global system level, it's impossible to recognize what is is, so it should work for any controls, which are very different and, generally, don't have anything in common.

If you just want to enter text in different languages, there is a civilized solution: creation and registration of a Windows keyboard layout. I explained it in detail in my past answer: Problem in typing in Hindi and english[^].

—SA


这篇关于GlobalKeyboardHook还是RegisterHotKey?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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