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
  • 144,904
  • 22
  • 145
  • 175
Jeremy
  • 43,100
  • 64
  • 198
  • 320

2 Answers2

21

Use KeyInterop.KeyFromVirtualKey().

Pang
  • 9,073
  • 146
  • 84
  • 117
xcud
  • 14,032
  • 3
  • 32
  • 28
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