Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.net

wpf

I'm developing application in WPF but some components are written using WinForms. I wan't these components to pull key gesture from WPF part and convert them to Keys enum (used in WinForms).

Is there a built in converter for that? (probably not) Do you know "easier than big switch case" method to do that?

like image 846
Sergej Andrejev Avatar asked Jul 20 '09 11:07

Sergej Andrejev


1 Answers

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.

like image 89
Sam Harwell Avatar answered Sep 22 '22 15:09

Sam Harwell