开发者

.net Keys Enumeration ToString() working with BackSlash '\'

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜