-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathKeyEvent.cpp
153 lines (135 loc) · 3.6 KB
/
KeyEvent.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file is part of CosmoScout VR //
////////////////////////////////////////////////////////////////////////////////////////////////////
// SPDX-FileCopyrightText: German Aerospace Center (DLR) <[email protected]>
// SPDX-License-Identifier: MIT
#include "KeyEvent.hpp"
#include <VistaKernel/InteractionManager/VistaKeyboardSystemControl.h>
namespace cs::gui {
////////////////////////////////////////////////////////////////////////////////////////////////////
KeyEvent::KeyEvent()
: mKey(Key::eUnknown) {
}
////////////////////////////////////////////////////////////////////////////////////////////////////
KeyEvent::KeyEvent(int key, int mods) {
mType = key < 0 ? KeyEvent::Type::eRelease : KeyEvent::Type::ePress;
mCharacter = static_cast<uint16_t>(key);
setMods(mods);
switch (std::abs(key)) {
case VISTA_KEY_F1:
mKey = Key::eF1;
return;
case VISTA_KEY_F2:
mKey = Key::eF2;
return;
case VISTA_KEY_F3:
mKey = Key::eF3;
return;
case VISTA_KEY_F4:
mKey = Key::eF4;
return;
case VISTA_KEY_F5:
mKey = Key::eF5;
return;
case VISTA_KEY_F6:
mKey = Key::eF6;
return;
case VISTA_KEY_F7:
mKey = Key::eF7;
return;
case VISTA_KEY_F8:
mKey = Key::eF8;
return;
case VISTA_KEY_F9:
mKey = Key::eF9;
return;
case VISTA_KEY_F10:
mKey = Key::eF10;
return;
case VISTA_KEY_F11:
mKey = Key::eF11;
return;
case VISTA_KEY_F12:
mKey = Key::eF12;
return;
case VISTA_KEY_LEFTARROW:
mKey = Key::eLeft;
return;
case VISTA_KEY_UPARROW:
mKey = Key::eUp;
return;
case VISTA_KEY_RIGHTARROW:
mKey = Key::eRight;
return;
case VISTA_KEY_DOWNARROW:
mKey = Key::eDown;
return;
case VISTA_KEY_PAGEUP:
mKey = Key::ePageUp;
return;
case VISTA_KEY_PAGEDOWN:
mKey = Key::ePageDown;
return;
case VISTA_KEY_HOME:
mKey = Key::eHome;
return;
case VISTA_KEY_END:
mKey = Key::eEnd;
return;
case VISTA_KEY_ESC:
mKey = Key::eEscape;
return;
case VISTA_KEY_ENTER:
mCharacter = '\n';
mType = key < 0 ? KeyEvent::Type::eInvalid : KeyEvent::Type::eCharacter;
mKey = Key::eReturn;
return;
case VISTA_KEY_TAB:
mCharacter = '\t';
mType = key < 0 ? KeyEvent::Type::eInvalid : KeyEvent::Type::eCharacter;
mKey = Key::eTab;
return;
case VISTA_KEY_BACKSPACE:
mKey = Key::eBackspace;
return;
case VISTA_KEY_DELETE:
mKey = Key::eKeyDelete;
return;
case VISTA_KEY_SHIFT_LEFT:
mKey = Key::eLeftShift;
return;
case VISTA_KEY_SHIFT_RIGHT:
mKey = Key::eRightShift;
return;
case VISTA_KEY_CTRL_LEFT:
mKey = Key::eLeftControl;
return;
case VISTA_KEY_CTRL_RIGHT:
mKey = Key::eRightControl;
return;
case VISTA_KEY_ALT_LEFT:
case VISTA_KEY_ALT_RIGHT:
mKey = Key::eAlt;
return;
}
if (key <= 0) {
mType = KeyEvent::Type::eInvalid;
return;
}
mType = KeyEvent::Type::eCharacter;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void KeyEvent::setMods(int mods) {
mModifiers = 0;
if (mods & VISTA_KEYMOD_SHIFT) {
mModifiers |= int(Modifier::eShift);
}
if (mods & VISTA_KEYMOD_CTRL) {
mModifiers |= int(Modifier::eControl);
}
if (mods & VISTA_KEYMOD_ALT) {
mModifiers |= int(Modifier::eAlt);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
} // namespace cs::gui