Results 1 to 3 of 3

Thread: Retrieve the state of specific keys

  1. #1
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Retrieve the state of specific keys

    Another question: While the mouse is moved, is there a way to know if a keyboard key such as A or 'X' is down (pressed) ?

    OK, it can be done by tracking the keyPress and keyRelease events, but it would be more convenient to just retrieve the keyboard state at any point in the program.

    Any clues ?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Retrieve the state of specific keys

    Note that at any point in time an arbitrary number of keys can be pressed. It would be hard and unusable to report the state of over 100 keys. You should track keyPress and keyRelease events yourself, don't be too lazy, it's just 6 lines of code in implementation and three lines of code in the header file.

  3. #3
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Retrieve the state of specific keys

    Well, thanks, I thought, or feared, that this might be the case.

    I'm coming from the MFC world, where there is the very convenient GetKeyState(key) function. My experience, still in the MFC world, is that keydown and keyup messages get lost occasionally, so that it's safer to ask the keyboard state when you need it.

    I'll try to track keypress and keyrelease events, and see how it goes.

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.