Results 1 to 6 of 6

Thread: Catch pressed keys

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Catch pressed keys

    Does QT have any way to check, at any moment, which keys are pressed in the keyboard?

    I'm thinking about set a bool variable when the keypress event is launched and set it to zero at keyrelease... but I'd like to know if there is any other way.

    thanks!

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Catch pressed keys

    Qt Code:
    1. int QKeyEvent::key ()
    To copy to clipboard, switch view to plain text mode 
    Returns the code of the key that was pressed or released. Use it in your keyPressEvent.

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Catch pressed keys

    "Behind every great fortune lies a crime" - Balzac

  4. #4
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Catch pressed keys

    yep, thanks, but I'm looking for something not inside the Qpressevent. I'd like to know it at any time, not just when a key is pressed.

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Catch pressed keys

    Quote Originally Posted by jano_alex_es View Post
    yep, thanks, but I'm looking for something not inside the Qpressevent. I'd like to know it at any time, not just when a key is pressed.
    how about my event filter code ..
    Qt Code:
    1. bool RecRepView:: eventFilter(QObject *ob, QEvent *e)
    2. {
    3. if(e->type() == QEvent::KeyPress){
    4. printf("is it coming inside event..\n");
    5. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    6. if(ke->key()==Qt::Key_F1){
    7. qApp->quit();
    8. printf("Logout buttin clicked..\n");
    9. }
    10. return true;
    11. }
    12. return QWidget::eventFilter(ob, e);
    13. }
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  6. The following user says thank you to wagmare for this useful post:

    jano_alex_es (30th July 2009)

  7. #6
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Catch pressed keys

    that definetly should work!

    thanks!

Similar Threads

  1. Can't See QToolButton pressed Signal from QTableWidget
    By mbrusati in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2008, 20:06
  2. Can't catch key_down and some keys
    By anafor2004 in forum Newbie
    Replies: 5
    Last Post: 27th February 2008, 09:00

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
  •  
Qt is a trademark of The Qt Company.