Accepting keyboard input in Silverlight Part 2

So accepting keyboard input isn’t too difficult, however, displaying the corresponding character seems to be a lot harder nut to crack. The basic problem is that the key codes received are ASCII based but that only vaguely relates to the keyboard. For example, a typical keyboard shift+6 would result in ^ but in ASCII the key code maps to ‘. This is before you start worrying about country layouts, e.g. the dreaded location of the double quote. I’m currently looking back to Win Forms to see how that handles the problem. I reflected so code out, I nice enum Keys which maps to the PlatformKeyCode returned in Silverlight. This does a good job of abstracting the keyboard but still doesn’t really help in displaying the correct character. So if I press 1 if get D1, or # (on a UK keyboard) returns oemPipe. This is fine for mapping a keyboard for something like a game, but not very helpful in echoing the character to the screen. So I’m looking at porting the KeyConverter classes, I’m doubtful this will work so I may have to resort to getting help from the browser via some JavaScript. If anyone knows of a better way the please let me know!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s