Results 1 to 4 of 4

Thread: Kana Lock Detection

  1. #1

    Default Kana Lock Detection

    Hi, I'm very new to Qt, but I have been recently been assigned to a project involving Qt & X11 in Linux (a flavor of Ubuntu). One of my tasks is to write a function to detect the state of caps lock, number lock, scroll lock, and Kana lock. So far, I have been able to detect caps, number, and scroll lock, but can't seem to figure out Kana lock. Does anyone know how to use XkbGetIndicatorState() to detect Kana lock? If not, does anyone know a better, or different, method that is capable of detecting the state of all four?


    My code for the other three is:

    //---------------------------------------------------
    Qt Code:
    1. #include <iostream>
    2. #include <X11/KBlib.h>
    3. #include <X11/Xlib.h>
    4.  
    5. using namespace std;
    6.  
    7. int main( int argc, char *argv[] ){
    8.  
    9. unsigned kbd_state, led_state=0;
    10. XkbGetIndicatorState( NULL, XkbUseCoreKbd, &kbd_state );
    11.  
    12. // here is the logic for lock detection
    13. if( (kbd_state & 0x01) == 1 ) led_state += 1; // if caps lock is on
    14. if( (kbd_state & 0x02) == 2 ) led_state += 2; // if number lock is on
    15. if( (kbd_state & 0x04) == 4 ) led_state += 4; // if scroll lock is on
    16. // if( (kbd_state & ????) == ? ) led_state += ?; // is kana lock on??????
    17.  
    18. return 0;
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    //---------------------------------------------------


    Any help would be really appreciated! Thanks!
    Last edited by high_flyer; 13th September 2011 at 09:47. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Kana Lock Detection

    Qt::Key_Kana_Lock ?
    Why not use the Qt enums for all the other keys as well?
    It will increase the portability of your code.
    Last edited by high_flyer; 13th September 2011 at 09:49.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3

    Default Re: Kana Lock Detection

    Seems to me that this key code is only useful for listening to see if the key is pressed or setting and unsetting its state. I need a way to determine whether or not it has already been pressed, so to speak. My application needs to know if caps lock is on or off, as well as for scroll/num/kana. Is there a function that will query the state of these locks in Qt?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Kana Lock Detection

    Well, you could use QApplication::keyboardModifiers (), but I see in the docs that the Kana lock is not part of the information it returns.
    What you can do however, is create an event filter, and filter the keyboard events, and set a flag each time the Kana_lock is pressed or released, so that you can know at later time its state.
    I also would experiment to see, if any of the modifiers are returned (such as Qt::AltModifier or Qt::MetaModifier) when the Kana_lock is on, might save you a bit of "if()"'s.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. lock a file
    By Malek in forum Newbie
    Replies: 2
    Last Post: 27th December 2010, 23:44
  2. Lock a file
    By euthymos in forum Qt Programming
    Replies: 22
    Last Post: 27th December 2010, 23:29
  3. Lock Screen
    By ahmdsd_ostora in forum Qt Programming
    Replies: 16
    Last Post: 11th July 2010, 09:55
  4. Lock strategy
    By pippo42 in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2010, 10:31
  5. QMutex seems not to lock()
    By sylvaticus in forum Qt Programming
    Replies: 18
    Last Post: 4th December 2009, 10:39

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.