Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the ascii dec number of a keypress in WPF

Tags:

c#

wpf

In winform, if i wanted to get the ascii code of a key pressed i would do like so:

Private void textbox1_KeyPress(object sender, KeyEventArgs e)
{
    int i = e.KeyChar;
}

how would i go about doing like so in WPF? Also, is KeyPress in winforms the equivalent of KeyDown in WPF?

like image 566
Bodokh Avatar asked Sep 19 '25 07:09

Bodokh


1 Answers

You need to capture the KeyDown event in WPF as follows:

    private void TextBox1_KeyDown(object sender, KeyEventArgs e)
    {
        int ascii = KeyInterop.VirtualKeyFromKey(e.Key);
    }
like image 127
Wagner DosAnjos Avatar answered Sep 20 '25 22:09

Wagner DosAnjos