winapikeyboard-layout

Get Physical Keyboard Layout Programmatically


Is there a way to programmatically find out what kind of keyboard a computer has (i.e. where keys are located, and what extra keys are present in which locations)?

A little error is acceptable, if the keyboard is very non-standard, but in general, the point is to construct an on-screen keyboard-like application that can dynamically draw the keyboard layout on the screen, with high accuracy.


Solution

  • There is no mechanism by which a keyboard can tell Windows what its physical layout looks like. Easy to see with the Windows version of an on-screen keyboard, osk.exe. It seems to be able to guess the form-factor of the machine (laptop vs desktop) but on my laptop it doesn't match the layout of the keyboard.

    Use the osk.exe layout as a template so nobody can complain that yours doesn't match well.