【问题标题】:In WPF , how to find out if a pressed key is a input key or not (one which prints something or not )?在 WPF 中,如何确定按下的键是否是输入键(打印或不打印的键)?
【发布时间】:2011-09-28 16:33:45
【问题描述】:

我有一些要求,我必须确定按下的键是否是输入键。

我有一个带有 previewkeydown 事件的 TextBox。

 <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
        // }
    }

请指导我如何去做。

【问题讨论】:

    标签: wpf keyboard ascii character key


    【解决方案1】:

    (int)e. 44 到 69 之间的键是字母。 90 到 113 之间是功能键。在反射器或 dotpeek 中反编译 System.Windows.Input.Key 枚举,您将获得所有键的值。

    【讨论】:

    • 组合按下时怎么样? Ctrl+Shift+A
    • 你必须寻找 Keyboard.Modifiers
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 2013-04-19
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多