On different machines, in an OnKeyDown
override, the e.Key
values are not necessarily consistent. For instance, on my Mac running Win7-64 under Boot Camp, the backslash key is reported as Key.OemQuote
and not Key.OemBackslash
as one would expect, which makes no sense considering that's not even on the same key. On a co-worker's Dell, it's reported as something else entirely.
However, in both cases, the correct backslash character is appearing in a textbox when typing so the OS obviously somehow knows that's what character that key is tied to.
We're trying to determine if, given a keycode on a particular system, you can get the corresponding character, if any, which that key represents (assuming no modifiers are pressed.)
Note: I am already aware of the OnPreviewTextInput
and OnTextInput
events which deal with the characters that are typed, but that is not what I am asking.
I am specifically asking about a function that takes a KeyCode as a parameter and returns what character would be displayed on-screen if that key were to be pressed.
For instance, on my machine, the function would take Key.OemQuote
and would return the backslash character. Passing in Key.Control
would return null
(since nothing actually appears when Control is pressed alone.)
Note: I've put up another question about dealing with the different key codes specifically that may look similar to this question, but this is a very specific separate question relating to a function that takes such a code and returns a character, so please do not mark this as a duplicate. It is not.