Thread: Detect keyboard layout (linux)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    8

    Detect keyboard layout (linux)

    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 by merwyn; 01-12-2016 at 05:03 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 10-12-2012, 02:39 AM
  2. C keyboard hooks for linux
    By codecaine_21 in forum C Programming
    Replies: 6
    Last Post: 11-10-2010, 09:25 PM
  3. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  4. Get windows Keyboard layout
    By PVoronin in forum Windows Programming
    Replies: 2
    Last Post: 09-19-2007, 04:27 AM
  5. Linux: Send keyboard input to background process
    By xErath in forum Tech Board
    Replies: 2
    Last Post: 12-09-2004, 07:02 PM