code_junkie

C# How to translate virtual keycode to char?

Nov 12th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  2. {
  3. const int WM_KEYDOWN = 0x100;
  4.  
  5. if (msg.Msg == WM_KEYDOWN)
  6. {
  7. // 2 is used to translate into an unshifted character value
  8. int nonVirtualKey = MapVirtualKey((uint)keyData, 2);
  9.  
  10. char mappedChar = Convert.ToChar(nonVirtualKey);
  11. }
  12.  
  13. return base.ProcessCmdKey(ref msg, keyData);
  14. }
  15.  
  16. KeysConverter kc = new KeysConverter();
  17. string keyChar = kc.ConvertToString(keyData);
Add Comment
Please, Sign In to add comment