I have an event handling a keypress (KeyDown) that has KeyEventArgs argument. This class has a few relevant members:
- KeyCode
- KeyData
- KeyValue
My problem is: Whenever I press BackSlash, I'd like to get a String with the single character "\".
W开发者_开发百科henever I call ToString() on any of the above characters, it just returns Oem5.
I know I could just throw it in a giant if clause, but I'd like to avoid that if I can.
Thanks!
Keyboard Mapping in .NET provides an answer, though it may be easier to use the KeyPress event than KeyDown. KeyDown works at the level of abstraction of the actual keyboard (bunch of keys, will differ according to locale and set-up and may have e.g. a two different sets of numbers, which you may wish to distinguish, and there may not even be a character if the key is a modifier or dead-accent key). KeyPress is better-equipped to deal with the level of abstraction of actual characters being input.
精彩评论