Get lowercase with keydown wpf

前端 未结 5 2114
再見小時候
再見小時候 2020-12-20 17:36

I want to get the keys pressed on the keyboard either with or without caplock:

private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 18:32

    You can't use the KeyDown event. You'll need to use the TextInput event. This will print the original letter with it's caption (Uppercase/Lowercase).

        private void Window_TextInput(object sender, TextCompositionEventArgs e)
        {
            Console.WriteLine(e.Text);
        }
    

    Now, this will also print the Shift and so on if it's pressed. If you don't want those modifiers just get the last item of the string -treat it as a char array ;)-

提交回复
热议问题