Search code examples
rubykeyboard-layout

Find out which keyboard layout is used, using ruby


How can I find out, which keyboard layout the user of my ruby application is using? My aim is to have a game, where you can move the player on a map. To go one step down and one step left you press "Y" on a german keyboard. On an American keyboard, you would press "Z". We optimized the game for windows and mac, so I would like a solution for both platforms (and we don't use any command/shift/control-keys).


Solution

  • As Alexander recommended, let the user define the keys themselves.

    But, if you really want to recognize the layout, you could always ask the user to press keys in certain positions, particular to some layouts.

    "Press the second key to the left of the return key. If your return key is two rows high, press the lower one"
    [presses ä]
    "Looks like you have a scandinavian keyboard"

    That, however, is a horrible cludge, and, in the game context, would recommend the custom keymapping method