获取有关Control.KeyDown炭? [英] Get the char on Control.KeyDown?
问题描述
在处理 Control.OnKey preSS
事件,有一个
包含主要pressEventArgs一个 KeyChar
。
When handling Control.OnKeyPress
event, there is a KeyPressEventArgs
that contains a KeyChar
.
有关可用性的原因,我需要完全一样的 KeyChar
,但处理时的onkeydown
事件。
For usability reasons I need exactly the same KeyChar
but when handling OnKeyDown
event.
在 KeyEventArgs
不包含任何字符有关的数据。我的意思是,如果preSS的 A
键带或不带移
它不影响键code
, KEYDATA
或 KEYVALUE
。同样使用另一种语言的时候,我仍然得到资本英语值。
The KeyEventArgs
does not contains any char related data. I mean, if press the A
key with or without Shift
its not affecting the KeyCode
, KeyData
or KeyValue
. The same when using another language, i still getting capital english values.
如何获得键pressEventArgs.KeyChar
在的KeyDown
事件?
感谢。
推荐答案
转换。下面是简单的功能,将A至A。它转换成唯一的资本字符的 [AZ] 设置。值32是差异'A'和'A'..当然,你可以把它扩展到您的要求,或要求此功能。
Convert it. Here is simple function for converting 'A' to 'a'. It converts only capital chars from [A-Z] set. The value 32 is diff between 'A' and 'a'.. Sure you can extend it to your requirements, or ask for feature here.
char getChar( KeyEventArgs e )
{
int keyValue = e.KeyValue;
if ( !e.Shift && keyValue >= (int) Keys.A && keyValue <= (int) Keys.Z )
return (char)(keyValue + 32);
return (char) keyValue;
}
如果你需要它与您当前的文化作品,你应该重写ProcessKeyMessage控制方式:
if you need it to works with your current culture you should override ProcessKeyMessage Control method:
protected override bool ProcessKeyMessage( ref Message m )
{
if ( ( m.Msg == 0x102 ) || ( m.Msg == 0x106 ) ) // this is special - don't remove
{
char c = (char) m.WParam; // here is your char for OnKeyDown event ;)
}
return base.ProcessKeyMessage( ref m );
}
希望它有帮助。
Hope it helpful.
这篇关于获取有关Control.KeyDown炭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!