Dirk's picture

Windows.Forms.Keys to OpenTK.Input.Keys

Hi,
is there an easy way to convert / map Windows.Forms.Keys to OpenTK.Input.Key ?

Because for example Windows.Forms.Keys.A == 0x41 and OpenTK.Input.Key.A == 0x53.

Thx


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
SatoshiChiba's picture

You could make a Dictionary Map...

Dictionary<Windows.Forms.Keys, OpenTK.Input.Key> keys = new Dictionary<Windows.Forms.Keys, OpenTK.Input.Key>();
 
//Then do:
keys.Add(Windows.Forms.Keys.A, OpenTK.Input.Key.A);

Then if you want to get the OpenTK equivalent of a pressed WinForms key just do: keys[Windows.Forms.Keys.A] and it will get you OpenTK.Input.Key.A
Of course to make such a list is boring work but you just have to type it one time :)

the Fiddler's picture

A large switch statement would be even faster than a dictionary.

c2woody's picture

But indeed a (static) function for OpenTK-Key to WinForms-Key might be nice, any chance/interest in having this in the library? Is "clear out all WinForms dependencies" (which I think is a really nice and want to have thing) a problem here?

Tal's picture

There is some overlap ranges in the enums, so I think it will be faster(little) to use "if, else if" statements. In those range, such as A-Z, just convert using:
(OpenTK.Input.Keys)formsKey + offset

c2woody's picture

From experience this is usually no good thing to do since the codes may be different on other platforms, or even change for one platform (the system is still consistent then unless something relies on the castdown to e.g. integer).