在 WPF 中,如何确定按下的键是否是输入键(是否打印某些内容)?
我有一些要求,我必须确定按下的键是否是输入键。
我有一个带有 Previewkeydown 事件的文本框。
<TextBox PreviewKeyDown="MyTextBox_PreviewKeyDown" ></TextBox>
然后我在这里有事件处理程序的代码
private void MyTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
//I need to find out here if key pressed is
// an input key something like
// if ( key is between a to z or 0 to 9 or some_character_input)
// {
//
// }
//else
//{
// Key is either F1,F2,UpArrow, DownArrow, etc
// }
}
请指导我如何使用它。
I am having some requirement in which I have to find out if the key pressed is a input key.
I have a TextBox with a previewkeydown event.
<TextBox PreviewKeyDown="MyTextBox_PreviewKeyDown" ></TextBox>
Then I have the code for event handler here
private void MyTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
//I need to find out here if key pressed is
// an input key something like
// if ( key is between a to z or 0 to 9 or some_character_input)
// {
//
// }
//else
//{
// Key is either F1,F2,UpArrow, DownArrow, etc
// }
}
Please guide me how to go about with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(int)e.44到69之间的键是字母。 90 到 113 之间是功能键。在反射器或 dotpeek 中反编译 System.Windows.Input.Key 枚举,您将获得所有键的值。
(int)e.Key between 44 and 69 are alphabets. Between 90 and 113 are function keys. Decompile System.Windows.Input.Key enum in reflector or dotpeek you will get values for all keys.