Results 1 to 2 of 2

Thread: How to get the current layout of keyboard

  1. #1
    Join Date
    Feb 2017
    Posts
    7
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default How to get the current layout of keyboard

    Hi,
    I need to know the current layout of keyboard.
    I cannot use QEvent::KeyboardLayoutChange (https://bugreports.qt.io/browse/QTBUG-27681) or QApplication::keyboardInputLocale() which is obsolete.

    The ideal solution would be to know exactly when user change keyboard layout. But I will be happy with any solution that give me the current layout of keyboard.
    PS This is a little game, not a text editor.

    Thanks for the time spent reading this message.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get the current layout of keyboard

    I do not know if there is really a way to get the actual physical layout of the keys on the keyboard. At the keyboard driver level, the driver certainly knows which physical key has which character on it, but by the time it gets to the application layer, all of the physical keys have been mapped to virtual keys and there isn't an API that lets you go backward to physical location (at least not that I know of in Qt anyway).

    Instead of trying to map specific keys to specific things in your game app yourself, why don't you let your users do it? For example, you could give them a default table of key -> action mappings ("A" = move left, "W" = move up, "S" = move left, "Z" = move down, for example) and then let them change them to suit their own preferences. Maybe someone has trouble using their left hand and wants to map these to the "O", "K", "L" and "," keys instead for right-hand use. Give them a "setup keyboard" UI that lets them change things to suit their own keyboard and personal preferences. All you have to do is to store these in a configuration file (try QSettings) and read it into an internal mapping table at run time.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. emacs keyboard layout on qtcreator
    By sajis997 in forum Newbie
    Replies: 0
    Last Post: 8th March 2012, 21:41
  2. How to change keyboard layout
    By somename in forum Qt Programming
    Replies: 5
    Last Post: 27th May 2010, 08:36
  3. QKeyEvent problem with different keyboard layout
    By minimoog in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2010, 06:45
  4. Keyboard layout
    By alisami in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2009, 07:31
  5. Replies: 0
    Last Post: 25th May 2009, 10:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.