views:

330

answers:

3

OK, this is a slightly weird question.

We have a touch-screen application (i.e., no keyboard). When users need to enter text, the application shows virtual keyboard - hand-built in WinForms.

Making these things by hand for each new language is monkey work. I figure that windows must have this keyboard layout information hiding somewhere in some dll. Would there be anyway to get this information out of windows?

Other ideas welcome (I figure at least generating the thing from a xml file has got to be better than doing it by hand in VS).

(Note: having said all which, I note that there is a Japanese keyboard, state machine and all..., so XML might not be sufficient)

UPDATE: pretty good series on this subject (I believe) here

A: 

Please check following Windows API

 [DllImport("user32.dll")]
 private static extern long LoadKeyboardLayout(string pwszKLID, uint Flags);

Check MSDN here

nils_gate
Hm, this just loads a keyboard layout in the current process/thread, it doesn't allow me to reproduce it visually (i.e., what key is in what position).
Benjol
Though you may be on to something here, apparently MapVirtualKey can map a scancode (hardware) to a VirtualKey, and GetKeyNameText can convert a scancode to a string...
Benjol
A: 

Why don't you use the on-screen keyboard (osk.exe)? Looks like you re-inventing the wheel. And not the easiest one!

Serge - appTranslator
A question of lookologie, I fear. Bear in mind this is a pre-wpf project where they recoded all the controls by hand, to make them prettier.
Benjol
It's also a tad small for a touch-screen.
ProfK
+1  A: 

Microsoft Keyboard Layout Creator can load system keyboards and export them as .klc files. Since it’s written in .NET you can use Reflector to see how it does that, and use reflection to drive it.

I’ve already done this once before, so here’s a tarball of all the .klc files for Windows XP. If you need the new layouts in Vista, re-run the code included in the tarball. It’s written in Mathematica but should be straightforward to translate to any other .NET-compatible language.

andrew
That is a cool answer! I'll have to give it a try...
Benjol