10

If I intercept a key press using win32 calls, I now have a key code. Is there a way to convert that to a System.Windows.Forms.Keys value?

bdukes
  • 152,002
  • 23
  • 148
  • 175
Jeremy
  • 44,950
  • 68
  • 206
  • 332

2 Answers2

22

Use KeyInterop.KeyFromVirtualKey().

Pang
  • 9,564
  • 146
  • 81
  • 122
xcud
  • 14,422
  • 3
  • 33
  • 29
10

The integer values for System.Windows.Forms.Keys enum match that of the Win32 calls.

Keys keyData = (Keys)rawWin32KeyCode;
Adam Larsen
  • 1,121
  • 1
  • 8
  • 13
  • This is not working if some modifier keys (shift, ctrl., alt) are pressed! lParam.vkCode = 160 // = VK_LSHIFT lParam.scanCode = 42 Keys key = (Keys)lParam.vkCode; key = Space | F17 – Jens Bornschein Jul 10 '18 at 13:44