If you're making a game, then you have a very simple solution... As you probably want your game to be stable independent of the computer it is running on, you should use a QTimer object (or a timer event) to synchronise your game loop. And if you do, you can simply check the key state there instead of relying on key press/release events. QSet might be helpfull here as well.
QSet<Qt::Key> keysPressed;
keysPressed += (Qt::Key)ev->key();
}
keysPressed -= (Qt::Key)ev->key();
}
foreach(Qt::Key k, keysPressed){
//...
}
}
QSet<Qt::Key> keysPressed;
void W::keyPressEvent(QKeyEvent *ev){
keysPressed += (Qt::Key)ev->key();
}
void W::keyReleaseEvent(QKeyEvent *ev){
keysPressed -= (Qt::Key)ev->key();
}
void W::timerEvent(QTimerEvent *ev){
foreach(Qt::Key k, keysPressed){
//...
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks