How can I convert ‘System.Windows.Input.Key’ to ‘System.Windows.Forms.Keys’?

Keys formsKey = ...;
Key wpfKey = ...;
wpfKey = KeyInterop.KeyFromVirtualKey((int)formsKey);
formsKey = (Keys)KeyInterop.VirtualKeyFromKey(wpfKey);

The KeyInterop class is the “key,” plus the fact that the Windows Forms Keys enumeration has the same integer values as the Win 32 virtual key codes.

Leave a Comment