I am trying to create a simple game in QT that uses event filter to catch keys pressed. It worked correctly until I implemented 'speed up' once space button is pressed. I have such a method in main window:
QSet<int> keysClicked; //declared in header
bool MainClass::eventFilter(QObject* target, QEvent* event)
{
if(event->type()==QEvent::KeyPress)
{
keysClicked.insert(static_cast<QKeyEvent*>(event)->key());
qDebug() << static_cast<QKeyEvent*>(event)->key();
}
else if(event->type()==QEvent::KeyRelease)
keysClicked.remove(static_cast<QKeyEvent*>(event)->key());
return QWidget::eventFilter(target, event);
}
and then a timer which sends keysClicked each n msecs to an object that we control.
keysClicked set should be able to contain all currently pressed keys.
And there is a problem, as it should contain spacebar, key_up, and either key_left or key_right:
- It works correctly when I am holding
spacebar, key_up and key_right - It doesn't work when I am holding
spacebar, key_up and key_left(left key press is not found in eventFilter) - It works correctly when I am holding
key_up and key_left
Could someone explain me what is the problem and how could I fix it? (point 2.)