陷阱C ++键盘挂钩中的特殊字符. [英] Trap Special characters in a C++ keyboard hook.

查看:83
本文介绍了陷阱C ++键盘挂钩中的特殊字符.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经写了一个普通的低级键盘钩子.我能够在其中正确捕获所有字母数字键.但是我无法捕获诸如@,#,$等特殊字符吗?等等.所有这些键都需要先按Shift键,然后再按另一个键.例子? ,我们需要按Shift +/键,例如@,我们需要按Shift和2键.

反正有陷阱这样的特殊字符吗?一些示例代码将非常有帮助.请注意,我正在使用C ++.

感谢您的帮助.

Hi ,

I have written a normal Low-level keyboard hook. I am able to trap correctly all alphanumeric keys in it. But am unable to trap special characters like @,#,$,? etc. All these keys require pressing of the Shift Key followed by an other key. Example for ? , we need to press Shift+ / keys and for say @ , we need to press Shift and 2 key.

Is there anyway to trap such special characters? Some sample code will be really helpful. Please note that I am using C++ .

Thanks for your help.

推荐答案

,?等等.所有这些键都需要先按Shift键,然后再按另一个键.例子? ,我们需要按Shift +/键,例如@,我们需要按Shift和2键.

反正有陷阱这样的特殊字符吗?一些示例代码将非常有帮助.请注意,我正在使用C ++.

谢谢您的帮助.
,? etc. All these keys require pressing of the Shift Key followed by an other key. Example for ? , we need to press Shift+ / keys and for say @ , we need to press Shift and 2 key.

Is there anyway to trap such special characters? Some sample code will be really helpful. Please note that I am using C++ .

Thanks for your help.


我相信您必须执行的操作以及我至少完成的方法是,在获取"其他"关键信息.即,如果您想捕获``?'',则捕获``/'',并测试是否按下了换档键.如果两个都成立,那就做陷阱的事情.
I believe the way that you have to do this, well the way I did it atleast, was to check for the status of the shift keys when you get the ''other'' key message. i.e If you wanted to catch ''?'', then trap ''/'', and test for shift keys being pressed. If both are true then do your trap stuff.
<pre><br />
if(key==''/'' && bShiftPressed)<br />
{<br />
    doTrapStuff();<br />
}</pre>


您正在混淆不同的抽象级别.
您所谓的特殊字符"一点也不特殊:它们只是常规字符.它们像"a"一样与"A"不同.
但是问题是您正在使用的输入"级别.
一个低级的钩子知道字符"的含义:它只知道键"(物理键),并且它们由它们的名称标识(通常,它与印刷在其上的主要字母相同,因此造成混淆) ).

字符是按键/释放顺序与键盘布局之间映射的结果,每个国家/地区之间的映射可能有所不同(例如,在我的键盘上,Shift + 2是"",而?id shift +''和@是Ctrl + Alt +ò
将键(或键弦)映射到字符的任务是键盘驱动程序的任务,该驱动程序处理您所钩住的低级事件.

如果要管理字符,请使用_getch()std::cin之类的面向字符的输入函数",或者使用其他面向控制台的字符函数(对于控制台应用程序)或处理WM_CHAR(但请确保您的messageloop调用TranslateMessage DispatchMessage)(如果是Win32 App).
You are confusing different abstraction level.
What you call "special characters" are not special at all: they''re just regular characters. They differ like an "a" differs form an "A".
But the problem is the level of "input" you are using.
A low level hook knows noting about "characters": it knows only about "keys" (the physical ones), and they are identified by their names (That - conventionally- are the same of the main letter printed on them - hence the confusion).

Characters are the result of a mapping between sequences of key pressures/releases and keyboard layout, that may be different from country to country (for example, on my keyboard, Shift+2 is ''"'' and and ? id shift+'' and @is Ctrl+Alt+ò
The task to map keys (or keychord) to characters is a task of the keybord driver, that handles the low level event you hooked.

If you want to manage characters use "character oriented input functions" like _getch() or std::cin or other console oriented character functions (in case of console app) or handle WM_CHAR (but ensure your messageloop calls TranslateMessage before DispatchMessage) in case of Win32 App.


这篇关于陷阱C ++键盘挂钩中的特殊字符.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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