-
Notifications
You must be signed in to change notification settings - Fork 14
/
keypressfilter.cpp
38 lines (36 loc) · 1.12 KB
/
keypressfilter.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
#include "keypressfilter.h"
#include "interface/core_commands.h"
#include "interface/common.h"
#include "mainwindow.h"
#include <QKeyEvent>
#include <QMessageBox>
KeyPressFilter::KeyPressFilter(QObject *parent)
: QObject(parent)
{
}
bool KeyPressFilter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
int modValue = QT2SDL2MOD(keyEvent->modifiers());
int keyValue = QT2SDL2(keyEvent->key());
if (keyValue != 0)
(*CoreDoCommand)(M64CMD_SEND_SDL_KEYDOWN, (modValue << 16) + keyValue, NULL);
return true;
}
else if (event->type() == QEvent::KeyRelease)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
int modValue = QT2SDL2MOD(keyEvent->modifiers());
int keyValue = QT2SDL2(keyEvent->key());
if (keyValue != 0)
(*CoreDoCommand)(M64CMD_SEND_SDL_KEYUP, (modValue << 16) + keyValue, NULL);
return true;
}
else
{
// standard event processing
return QObject::eventFilter(obj, event);
}
}