-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyreceiver.cpp
47 lines (42 loc) · 1.18 KB
/
keyreceiver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "keyreceiver.h"
#include <QKeyEvent>
#include <QObject>
#include <iostream>
bool KeyReceiver::eventFilter(QObject* obj, QEvent* event)
{
if (event->type()==QEvent::KeyPress) {
QKeyEvent* key = static_cast<QKeyEvent*>(event);
if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) {
//Enter or return was pressed
std::cout << "received enter key" << std::endl;
}
else if(key->key() == Qt::Key_W) {
std::cout << "received w key" << std::endl;
emit w_key();
//return true;
}
else if(key->key() == Qt::Key_A) {
emit a_key();
//return true;
}
else if(key->key() == Qt::Key_S) {
emit s_key();
//return true;
}
else if(key->key() == Qt::Key_D) {
emit d_key();
//return true;
}
else{
return QObject::eventFilter(obj, event);
}
return true;
} else if(event->type()==QEvent::KeyRelease) {
emit key_release();
return true;
}
else {
return QObject::eventFilter(obj, event);
}
return false;
}