Alex Rivera | Logout

How to get pressed char from System.Windows.Input.KeyEventArgs?

Asked 2011-08-18T06:39:46.253
18

I have System.Windows.Input.KeyEventArgs e variable. I want to get real char. For example, i press } button on keyboard. And normally it returns string like oem.. but i want to get } char. How to do ?

[EDIT] I use this in TextBox .

Edit
Report

1 Answer

1

You have e.Key property you can use for just that. Here's a link to msdn.

Edit:
I didn't realize you need the actual char. You can take a look here They say that in WPF you can do it using some Win32 APIs, while in Silverlight it seems rather difficult. Also you can look at KeyInterop.VirtualKeyFromKey - you can convert the WPF Key enum into a WinForms Keys enumeration, which does give you some more information. I haven't tried any of the solutions, so I don't know if any of them will work.
And one last thing. Why do you need the char from the KeyDown/Up event? Are you sure you can't use the TextChanged event instead? It will be much easier to get the exact char, if you can.

answered 2011-08-18T06:53:03.457

Your Answer