TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
qglobalshortcut_win.cpp
Go to the documentation of this file.
1 #include "qglobalshortcut_p.h"
2 #define WIN32_LEAN_AND_MEAN
3 #include <qt_windows.h>
4 
5 #if !TTK_QT_VERSION_CHECK(5,0,0)
6 bool QGlobalShortcutPrivate::eventFilter(void* message)
7 #else
8 bool QGlobalShortcutPrivate::nativeEventFilter(const QByteArray &, void *message, qint *)
9 #endif
10 {
11  MSG *msg = TTKStaticCast(MSG*, message);
12  if(msg->message == WM_HOTKEY)
13  {
14  const quint32 keycode = HIWORD(msg->lParam);
15  const quint32 modifiers = LOWORD(msg->lParam);
16  activateShortcut(keycode, modifiers);
17  }
18  return false;
19 }
20 
21 quint32 QGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
22 {
23  // MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN
24  quint32 native = 0;
25  if(modifiers & Qt::ShiftModifier)
26  native |= MOD_SHIFT;
27  if(modifiers & Qt::ControlModifier)
28  native |= MOD_CONTROL;
29  if(modifiers & Qt::AltModifier)
30  native |= MOD_ALT;
31  if(modifiers & Qt::MetaModifier)
32  native |= MOD_WIN;
33  // TODO: resolve these?
34  //if(modifiers & Qt::KeypadModifier)
35  //if(modifiers & Qt::GroupSwitchModifier)
36  return native;
37 }
38 
40 {
41  switch (key)
42  {
43  case Qt::Key_Escape:
44  return VK_ESCAPE;
45  case Qt::Key_Tab:
46  case Qt::Key_Backtab:
47  return VK_TAB;
48  case Qt::Key_Backspace:
49  return VK_BACK;
50  case Qt::Key_Return:
51  case Qt::Key_Enter:
52  return VK_RETURN;
53  case Qt::Key_Insert:
54  return VK_INSERT;
55  case Qt::Key_Delete:
56  return VK_DELETE;
57  case Qt::Key_Pause:
58  return VK_PAUSE;
59  case Qt::Key_Print:
60  return VK_PRINT;
61  case Qt::Key_Clear:
62  return VK_CLEAR;
63  case Qt::Key_Home:
64  return VK_HOME;
65  case Qt::Key_End:
66  return VK_END;
67  case Qt::Key_Left:
68  return VK_LEFT;
69  case Qt::Key_Up:
70  return VK_UP;
71  case Qt::Key_Right:
72  return VK_RIGHT;
73  case Qt::Key_Down:
74  return VK_DOWN;
75  case Qt::Key_PageUp:
76  return VK_PRIOR;
77  case Qt::Key_PageDown:
78  return VK_NEXT;
79  case Qt::Key_F1:
80  return VK_F1;
81  case Qt::Key_F2:
82  return VK_F2;
83  case Qt::Key_F3:
84  return VK_F3;
85  case Qt::Key_F4:
86  return VK_F4;
87  case Qt::Key_F5:
88  return VK_F5;
89  case Qt::Key_F6:
90  return VK_F6;
91  case Qt::Key_F7:
92  return VK_F7;
93  case Qt::Key_F8:
94  return VK_F8;
95  case Qt::Key_F9:
96  return VK_F9;
97  case Qt::Key_F10:
98  return VK_F10;
99  case Qt::Key_F11:
100  return VK_F11;
101  case Qt::Key_F12:
102  return VK_F12;
103  case Qt::Key_F13:
104  return VK_F13;
105  case Qt::Key_F14:
106  return VK_F14;
107  case Qt::Key_F15:
108  return VK_F15;
109  case Qt::Key_F16:
110  return VK_F16;
111  case Qt::Key_F17:
112  return VK_F17;
113  case Qt::Key_F18:
114  return VK_F18;
115  case Qt::Key_F19:
116  return VK_F19;
117  case Qt::Key_F20:
118  return VK_F20;
119  case Qt::Key_F21:
120  return VK_F21;
121  case Qt::Key_F22:
122  return VK_F22;
123  case Qt::Key_F23:
124  return VK_F23;
125  case Qt::Key_F24:
126  return VK_F24;
127  case Qt::Key_Space:
128  return VK_SPACE;
129  case Qt::Key_Asterisk:
130  return VK_MULTIPLY;
131  case Qt::Key_Plus:
132  return VK_ADD;
133  case Qt::Key_Comma:
134  return VK_SEPARATOR;
135  case Qt::Key_Minus:
136  return VK_SUBTRACT;
137  case Qt::Key_Slash:
138  return VK_DIVIDE;
139 
140  // numbers
141  case Qt::Key_0:
142  case Qt::Key_1:
143  case Qt::Key_2:
144  case Qt::Key_3:
145  case Qt::Key_4:
146  case Qt::Key_5:
147  case Qt::Key_6:
148  case Qt::Key_7:
149  case Qt::Key_8:
150  case Qt::Key_9:
151  return key;
152 
153  // letters
154  case Qt::Key_A:
155  case Qt::Key_B:
156  case Qt::Key_C:
157  case Qt::Key_D:
158  case Qt::Key_E:
159  case Qt::Key_F:
160  case Qt::Key_G:
161  case Qt::Key_H:
162  case Qt::Key_I:
163  case Qt::Key_J:
164  case Qt::Key_K:
165  case Qt::Key_L:
166  case Qt::Key_M:
167  case Qt::Key_N:
168  case Qt::Key_O:
169  case Qt::Key_P:
170  case Qt::Key_Q:
171  case Qt::Key_R:
172  case Qt::Key_S:
173  case Qt::Key_T:
174  case Qt::Key_U:
175  case Qt::Key_V:
176  case Qt::Key_W:
177  case Qt::Key_X:
178  case Qt::Key_Y:
179  case Qt::Key_Z:
180  return key;
181 
182  default:
183  return 0;
184  }
185 }
186 
187 bool QGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
188 {
189  return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey);
190 }
191 
192 bool QGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
193 {
194  return UnregisterHotKey(0, nativeMods ^ nativeKey);
195 }
static quint32 nativeKeycode(Qt::Key keycode)
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
static constexpr wchar_t key[]
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers)
#define qint
Definition: ttkqtglobal.h:168
static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
static bool eventFilter(void *message)
static bool registerShortcut(quint32 nativeKey, quint32 nativeMods)