I have a program where for example if I hold down W then D everything works fine, however if I then release D it seems KeyPressEvent or KeyReleaseEvent do not trigger for w, I have checked this using qDebug, this occurs for any sequence of keys as long as they are pressed and depressed in the order specified above. But it seems that Renderarea is still being called somehow...
void RCcar::keyPressEvent(QKeyEvent* event) {
//sendMove->sendData(5);
if (event->key() == Qt::Key_A) {
Renderarea->is_pressed[0] = true;
if (Renderarea->is_pressed[1]) {
sendMove->sendData(4);
}
else if (Renderarea->is_pressed[3]) {
sendMove->sendData(3);
sendMove->sendData(0);
}
else {
sendMove->sendData(0);
}
Renderarea->update();
}
if (event->key() == Qt::Key_D) {
Renderarea->is_pressed[1] = true;
if (Renderarea->is_pressed[0]) {
sendMove->sendData(4);
}
else if (Renderarea->is_pressed[3]) {
sendMove->sendData(3);
sendMove->sendData(1);
}
else {
sendMove->sendData(1);
}
Renderarea->update();
}
if (event->key() == Qt::Key_S) {
Renderarea->is_pressed[2] = true;
if (Renderarea->is_pressed[3]) {
sendMove->sendData(4);
}
else {
sendMove->sendData(2);
}
Renderarea->update();
}
if (event->key() == Qt::Key_W) {
Renderarea->is_pressed[3] = true;
if (Renderarea->is_pressed[2]) {
sendMove->sendData(4);
}
else if (Renderarea->is_pressed[0]) {
sendMove->sendData(3);
sendMove->sendData(0);
}
else if (Renderarea->is_pressed[1]) {
sendMove->sendData(3);
sendMove->sendData(1);
}
else {
sendMove->sendData(3);
}
Renderarea->update();
qDebug() << test;
}
test++;
}
void RCcar::keyReleaseEvent(QKeyEvent* event) {
qDebug() << "hahaha";
sendMove->sendData(5);
if (!event->isAutoRepeat()) {
sendMove->sendData(4);
if (event->key() == Qt::Key_A) {
Renderarea->is_pressed[0] = false;
Renderarea->update();
return;
}
if (event->key() == Qt::Key_D) {
Renderarea->is_pressed[1] = false;
Renderarea->update();
return;
}
if (event->key() == Qt::Key_S) {
Renderarea->is_pressed[2] = false;
Renderarea->update();
}
if (event->key() == Qt::Key_W) {
Renderarea->is_pressed[3] = false;
Renderarea->update();
return;
}
}
}
So just to make it perfectly clear what is happening, If I press and hold down w then the console prints the integer test and "hahaha" alternating, if I then press down d while still holding down w, it just prints "hahaha" and I know its calling Key_D from keypressevent, if I then stop pressing d then the console doesn't print anything even though I am still holding down the w button.
thanks