
Text-input, shift modifier.
Posted Saturday, 27 August, 2011 - 18:14 by james_lohr inI'd like to have text input within my game, and so I'd like to map key presses to their corresponding characters, complete with shift modifiers.
I can do this manually by mapping ranges to keys, e.g. :
char keyChar; kval = (int)e.Key; if (kval >= (int)Key.A && kval <= (int)Key.Z) int val = kval - (int)Key.Number0; if (!shiftDown) { val += (int)'a'; } else { val += (int)'A'; } keyChar = (char)val; }
However, it's a bit painful to do this for every key on the keyboard, plus I'm sure it may vary depending on keyboard.
Is there a correct/better way of doing this?
Cheers,
James L.


Comments
Re: Text-input, shift modifier.
The KeyPress event does this translation for you.
Re: Text-input, shift modifier.
So it does! Thank you, that was easy. :)
I hadn't spotted it because I was expecting it to be in OpenTK.Input, but I appreciate that it depends on the native window and therefore needs to live where it is.