Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 770
user541686 Avatar asked Jan 21 '23 17:01

user541686


1 Answers

when connected to a computer, keyboards sends "scan codes" to the operating system. on windows, scan codes are then converted into virtual keys (a hardware independent mapping of the keyboard) then to real characters.

the MapVirtualKeyEx() function of the windows API allows you to translate between scan codes, virtual keys and characters. it should also be able to tell you if a key is non-existing.

together with GetKeyboardLayout() which tells you which keybaord is active at any point in time (keyboard layout can be different for different running applications), it should allow you to build a pretty accurate map of the keyboard.

anyway, have a look at the keyboard input section of the MSDN

i will add that all keyboards have almost the same layout. although there is no way to know where a key is physically located, you can probably guess from the scan code and basic knowledge of your own keyboards.

like image 104
Adrien Plisson Avatar answered Feb 04 '23 03:02

Adrien Plisson