Detect keyboard layout

Hello everyone, I am working on a code which use osg and keyboard input.
I have implemented an eventHandler in osg which do action on keyboard input, but I want it to be independant of the keyboard layout :
I use "wasd" key to move with a qwerty keyboard (like in any fps games), but if the user have an azerty keyboard I want to use "zqsd" key.

My first solution was to use the keyCode instead of keySymbol. It worked well in my computer : the keyCodes are the same if I use a azerty or qwerty layout. But I have read that it depend on the hardware and driver ... So I revert my change and use KeySymbol but I first detect the keyboard layout and change the control key.
In order to detect the keyboard layout I call the command "setxkbmap -print" and parse the output (the second line contain either "aliases(qwerty)" or "aliases(azerty)".

I'm not really satisified with this answer because in my (short) experience, system call and parsing output can be source of portability issues and are hard to maintain. Is there any better options ?

note : the users will most likely have ubuntu 10.04 to 14.04 distribution (64 and 32 bits if that change anything)

Thanks !
Last edited on
You may simply ask the user at the beginning what keyboard it is and save that in a file (so that you don't ask again).
The issue is that this is supposed to be a very simple viewer, without any menu or option or config file. It's part of a bigger project and i can't change that.

I shouldn't display text or information in the viewer, only a 3D scene.
Topic archived. No new replies allowed.