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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/* Copyright (c) 2015, Stanislaw Halik <sthalik@misaki.pl>
* Permission to use, copy, modify, and/or distribute this
* software for any purpose with or without fee is hereby granted,
* provided that the above copyright notice and this permission
* notice appear in all copies.
*/
#if defined(_WIN32)
# ifndef DIRECTINPUT_VERSION
# define DIRECTINPUT_VERSION 0x800
# endif
# include <dinput.h>
#include "win32-shortcuts.h"
#include <QList>
#include <QVariant>
#include <QDebug>
QList<win_key> windows_key_mods =
QList<win_key>{
{DIK_LCONTROL, Qt::Key_Control},
{DIK_RCONTROL, Qt::Key_Control},
{DIK_LALT, Qt::Key_Alt},
{DIK_RALT, Qt::Key_Alt},
{DIK_LSHIFT, Qt::Key_Shift},
{DIK_RSHIFT, Qt::Key_Shift},
{DIK_LWIN, Qt::Key_Super_L},
{DIK_RWIN, Qt::Key_Super_R},
};
QList<win_key> windows_key_sequences =
QList<win_key>{
{DIK_F1, Qt::Key_F1 },
{DIK_F2, Qt::Key_F2 },
{DIK_F3, Qt::Key_F3 },
{DIK_F4, Qt::Key_F4 },
{DIK_F5, Qt::Key_F5 },
{DIK_F6, Qt::Key_F6 },
{DIK_F7, Qt::Key_F7 },
{DIK_F8, Qt::Key_F8 },
{DIK_F9, Qt::Key_F9 },
{DIK_F10, Qt::Key_F10 },
{DIK_F11, Qt::Key_F11 },
{DIK_F12, Qt::Key_F12 },
{DIK_LEFT, Qt::Key_Left },
{DIK_RIGHT, Qt::Key_Right },
{DIK_UP, Qt::Key_Up },
{DIK_DOWN, Qt::Key_Down },
{DIK_PRIOR, Qt::Key_PageUp },
{DIK_NEXT, Qt::Key_PageDown },
{DIK_HOME, Qt::Key_Home },
{DIK_END, Qt::Key_End },
{DIK_BACK, Qt::Key_Backspace },
{DIK_COMMA, Qt::Key_Comma },
{DIK_PERIOD, Qt::Key_Period },
{DIK_LBRACKET, Qt::Key_BracketLeft },
{DIK_RBRACKET, Qt::Key_BracketRight },
{DIK_SEMICOLON, Qt::Key_Semicolon },
{DIK_SLASH, Qt::Key_Slash },
{DIK_BACKSLASH, Qt::Key_Backslash },
{DIK_BACKSPACE, Qt::Key_Backspace },
{DIK_APOSTROPHE, Qt::Key_Apostrophe },
{DIK_GRAVE, Qt::Key_QuoteLeft },
{DIK_MINUS, Qt::Key_Minus },
{DIK_EQUALS, Qt::Key_Equal },
{DIK_PERIOD, Qt::Key_Period },
{DIK_F1, Qt::Key_F1 },
{DIK_F2, Qt::Key_F2 },
{DIK_F3, Qt::Key_F3 },
{DIK_F4, Qt::Key_F4 },
{DIK_F5, Qt::Key_F5 },
{DIK_F6, Qt::Key_F6 },
{DIK_F7, Qt::Key_F7 },
{DIK_F8, Qt::Key_F8 },
{DIK_F9, Qt::Key_F9 },
{DIK_F10, Qt::Key_F10 },
{DIK_F11, Qt::Key_F11 },
{DIK_F12, Qt::Key_F12 },
{DIK_0, Qt::Key_0 },
{DIK_1, Qt::Key_1 },
{DIK_2, Qt::Key_2 },
{DIK_3, Qt::Key_3 },
{DIK_4, Qt::Key_4 },
{DIK_5, Qt::Key_5 },
{DIK_6, Qt::Key_6 },
{DIK_7, Qt::Key_7 },
{DIK_8, Qt::Key_8 },
{DIK_9, Qt::Key_9 },
{DIK_A, Qt::Key_A },
{DIK_B, Qt::Key_B },
{DIK_C, Qt::Key_C },
{DIK_D, Qt::Key_D },
{DIK_E, Qt::Key_E },
{DIK_F, Qt::Key_F },
{DIK_G, Qt::Key_G },
{DIK_H, Qt::Key_H },
{DIK_I, Qt::Key_I },
{DIK_J, Qt::Key_J },
{DIK_K, Qt::Key_K },
{DIK_L, Qt::Key_L },
{DIK_M, Qt::Key_M },
{DIK_N, Qt::Key_N },
{DIK_O, Qt::Key_O },
{DIK_P, Qt::Key_P },
{DIK_Q, Qt::Key_Q },
{DIK_R, Qt::Key_R },
{DIK_S, Qt::Key_S },
{DIK_T, Qt::Key_T },
{DIK_U, Qt::Key_U },
{DIK_V, Qt::Key_V },
{DIK_W, Qt::Key_W },
{DIK_X, Qt::Key_X },
{DIK_Y, Qt::Key_Y },
{DIK_Z, Qt::Key_Z },
{DIK_TAB, Qt::Key_Tab },
{DIK_RETURN, Qt::Key_Return},
{DIK_INSERT, Qt::Key_Insert},
{DIK_DELETE, Qt::Key_Delete},
{DIK_SPACE, Qt::Key_Space},
{DIK_SYSRQ, Qt::Key_Print},
{DIK_SCROLL, Qt::Key_ScrollLock},
{DIK_PAUSE, Qt::Key_Pause},
{DIK_NUMLOCK, Qt::Key_NumLock},
{DIK_CAPSLOCK, Qt::Key_CapsLock},
#define mod(x, y) static_cast<Qt::Key>(x | y)
{DIK_NUMPAD0, mod(Qt::Key_0, Qt::KeypadModifier)},
{DIK_NUMPAD0, mod(Qt::Key_0, Qt::KeypadModifier)},
{DIK_NUMPAD1, mod(Qt::Key_1, Qt::KeypadModifier)},
{DIK_NUMPAD2, mod(Qt::Key_2, Qt::KeypadModifier)},
{DIK_NUMPAD3, mod(Qt::Key_3, Qt::KeypadModifier)},
{DIK_NUMPAD4, mod(Qt::Key_4, Qt::KeypadModifier)},
{DIK_NUMPAD5, mod(Qt::Key_5, Qt::KeypadModifier)},
{DIK_NUMPAD6, mod(Qt::Key_6, Qt::KeypadModifier)},
{DIK_NUMPAD7, mod(Qt::Key_7, Qt::KeypadModifier)},
{DIK_NUMPAD8, mod(Qt::Key_8, Qt::KeypadModifier)},
{DIK_NUMPAD9, mod(Qt::Key_9, Qt::KeypadModifier)},
{DIK_NUMPADCOMMA, mod(Qt::Key_Comma, Qt::KeypadModifier)},
{DIK_NUMPADENTER, mod(Qt::Key_Enter, Qt::KeypadModifier)},
{DIK_NUMPADEQUALS, mod(Qt::Key_Equal, Qt::KeypadModifier)},
{DIK_NUMPADMINUS, mod(Qt::Key_Minus, Qt::KeypadModifier)},
{DIK_NUMPADPERIOD, mod(Qt::Key_Period, Qt::KeypadModifier)},
{DIK_NUMPADPLUS, mod(Qt::Key_Plus, Qt::KeypadModifier)},
{DIK_NUMPADSLASH, mod(Qt::Key_Slash, Qt::KeypadModifier)},
{DIK_NUMPADSTAR, mod(Qt::Key_multiply, Qt::KeypadModifier)},
};
bool win_key::to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods)
{
for (auto& wk : windows_key_sequences)
{
if (wk.win == k.keycode)
{
qt_ = wk.qt;
mods = Qt::NoModifier;
if (k.ctrl) mods |= Qt::ControlModifier;
if (k.shift) mods |= Qt::ShiftModifier;
if (k.alt) mods |= Qt::AltModifier;
return true;
}
}
return false;
}
bool win_key::from_qt(QKeySequence qt_, int& dik, Qt::KeyboardModifiers& mods)
{
// CAVEAT don't use QVariant::toUInt() or conversion fails
const unsigned qt = static_cast<unsigned>(QVariant(qt_).toInt());
const unsigned our_mods = unsigned(qt & Qt::KeyboardModifierMask);
{
const auto key_ = qt;
for (auto& wk : windows_key_sequences)
{
if (wk.qt == key_)
{
dik = wk.win;
mods = Qt::NoModifier;
return true;
}
}
}
{
const unsigned key = qt & ~Qt::KeyboardModifierMask;
for (auto& wk : windows_key_sequences)
{
if (wk.qt == key)
{
dik = wk.win;
mods = static_cast<Qt::KeyboardModifiers>(our_mods);
return true;
}
}
}
return false;
}
#endif
|