How to convert from Virtual Key codes to System.Windows.Forms.Keys
17,316
Solution 1
The integer values for System.Windows.Forms.Keys enum match that of the Win32 calls.
Keys keyData = (Keys)rawWin32KeyCode;
Solution 2
Use KeyInterop.KeyFromVirtualKey()
.
Comments
-
Jeremy almost 2 years
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?
-
xcud about 15 yearsIf the int and char keycode are interchangeable then this previous solution should work: <a href="stackoverflow.com/questions/544141/…>
-
whale70 almost 6 yearsThe question was about WinForms; KeyInterop is a WPF class not available under WinForms
-
Jens Bornschein almost 6 yearsThis 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