summaryrefslogtreecommitdiffhomepage
path: root/gui/keyboard.cpp
blob: b9964ecb2a617c711a772dc9d7778e150a75a42f (plain)
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
48
49
50
51
52
53
#include "keyboard.h"

#include <QDebug>

keyboard_listener::keyboard_listener(QWidget* parent) :
    QDialog(parent)
#if defined _WIN32
  , token([this](const Key& k) {
        if(k.guid != "")
        {
            int mods = 0;
            if (k.alt) mods |= Qt::AltModifier;
            if (k.shift) mods |= Qt::ShiftModifier;
            if (k.ctrl) mods |= Qt::ControlModifier;
            emit joystick_button_pressed(k.guid, k.keycode | mods, k.held);
        }
        else
        {
            Qt::KeyboardModifiers m;
            QKeySequence k_;
            if (win_key::to_qt(k, k_, m))
                emit key_pressed(static_cast<QVariant>(k_).toInt() | m);
        }
    })
// token initializer ends, real ctor body begins
#endif
{
    ui.setupUi(this);
    setFocusPolicy(Qt::StrongFocus);
}

#if !defined _WIN32
void keyboard_listener::keyPressEvent(QKeyEvent* event)
{
    switch (event->key())
    {
    case Qt::Key_Control:
    case Qt::Key_Shift:
    case Qt::Key_Meta:
    case Qt::Key_Alt:
    case Qt::Key_AltGr:
    case Qt::Key_NumLock:
        break;
    case Qt::Key_Escape:
        close();
        break;

    default:
        emit key_pressed(QKeySequence(event->key() | event->modifiers()));
        break;
    }
}
#endif