PDA

View Full Version : Catch pressed keys



jano_alex_es
30th July 2009, 12:07
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!

yogeshgokul
30th July 2009, 12:11
int QKeyEvent::key ()
Returns the code of the key that was pressed or released. Use it in your keyPressEvent.

wagmare
30th July 2009, 12:22
third post of this thread
http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-catch-enter-with-keypress-670.html

jano_alex_es
30th July 2009, 12:24
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.

wagmare
30th July 2009, 12:27
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 ..

bool RecRepView:: eventFilter(QObject *ob, QEvent *e)
{
if(e->type() == QEvent::KeyPress){
printf("is it coming inside event..\n");
const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if(ke->key()==Qt::Key_F1){
qApp->quit();
printf("Logout buttin clicked..\n");
}
return true;
}
return QWidget::eventFilter(ob, e);
}

jano_alex_es
30th July 2009, 12:32
that definetly should work! :)

thanks!