How can a program automatically detect the keyboard layout?


How can a program automatically detect the keyboard layout?

I am making a computer game (using GameMaker by YoyoGames), and I know that different keyboard types exist, such as QWERTY, AZERTY, QZERTY and others.

I want to make my game in such a way that the keyboard controls will depend on the keyboard type, so that all players can have the controls at the same physical positions, regardless of the letters of the keyboard buttons.

Is there a way, e.g. by using a batch file or whatever, that I can cause my program to return (identify and tell me) the layout of the keyboard?


You might be able to query the Windows keyboard layout files, but even that’s going to be hit or miss. There is a Windows API for it, but unless GameMaker has mapped that function, you won’t be able to access it in your game code.

Rather than try to guess the keyboard layout, you should just let the user define their own keyboard commands, so they can use any key they like. I remap keys to some degree in nearly every game I play, to try to get the same commands on the same keys (the whole "this game uses “E” for interact and another game uses “F” drives me nuts.)


Thank you for your answer.

I ask the administrator(-s) of this forum to not close this topic yet.

I want to do some research on my question. If I find a solution I intend to share it here, so that other people can benefit.

Thanks in advance to the administrators.


There are many keyboard layouts. See the Wikipedia writing called “Keyboard layout”.

So I will not bother myself trying to adapt to all of them.

As wilsontp proposed, I prefer to let user choose keyboard buttons.