Your third approach seems to be correct since you aren't using animations.
Use QKeyEvent::isAutoRepeat () to find out if your handling an 'real' key press.
For fluid motion when a key is pressed i suggest you start a timer when a key is pressed and kill it when all keys have been released. You could use a QSet to keep track of pressed keys.
//member
QSet<int> pressedKeys;
{
if(e->isAutoRepeat())
return;
if(pressedKeys.isEmpty())
startTimer(40);
pressedKeys.insert(e->key());
}
{
if(pressedKeys.contains(Qt::Key_Up))
...;
if(pressedKeys.contains(Qt::Key_Left))
...;
updateGL();
}
{
pressedKeys.remove(e->key());
if(pressedKeys.isEmpty())
startTimer(40);
}
//member
QSet<int> pressedKeys;
void keyPressEvent(QKeyEvent* e)
{
if(e->isAutoRepeat())
return;
if(pressedKeys.isEmpty())
startTimer(40);
pressedKeys.insert(e->key());
}
void timerEvent(QTimerEvent* e)
{
if(pressedKeys.contains(Qt::Key_Up))
...;
if(pressedKeys.contains(Qt::Key_Left))
...;
updateGL();
}
void keyReleaseEvent(QKeyEvent* e)
{
pressedKeys.remove(e->key());
if(pressedKeys.isEmpty())
startTimer(40);
}
To copy to clipboard, switch view to plain text mode
This way you should be able to catch any combination of keys being pressed.
Bookmarks