Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qwindowskeymapper.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qwindowskeymapper.h"
5#include "qwindowscontext.h"
7#include "qwindowswindow.h"
9
10#include <QtGui/qguiapplication.h>
11#include <QtGui/qwindow.h>
12#include <qpa/qwindowsysteminterface.h>
13#include <private/qguiapplication_p.h>
14#include <private/qhighdpiscaling_p.h>
15#include <QtGui/qevent.h>
16#include <QtGui/private/qwindowsguieventdispatcher_p.h>
17#include <QtCore/private/qdebug_p.h>
18#include <QtCore/private/qtools_p.h>
19
20#if defined(WM_APPCOMMAND)
21# ifndef FAPPCOMMAND_MOUSE
22# define FAPPCOMMAND_MOUSE 0x8000
23# endif
24# ifndef FAPPCOMMAND_KEY
25# define FAPPCOMMAND_KEY 0
26# endif
27# ifndef FAPPCOMMAND_OEM
28# define FAPPCOMMAND_OEM 0x1000
29# endif
30# ifndef FAPPCOMMAND_MASK
31# define FAPPCOMMAND_MASK 0xF000
32# endif
33# ifndef GET_APPCOMMAND_LPARAM
34# define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
35# endif
36# ifndef GET_DEVICE_LPARAM
37# define GET_DEVICE_LPARAM(lParam) ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
38# endif
39# ifndef GET_MOUSEORKEY_LPARAM
40# define GET_MOUSEORKEY_LPARAM GET_DEVICE_LPARAM
41# endif
42# ifndef GET_FLAGS_LPARAM
43# define GET_FLAGS_LPARAM(lParam) (LOWORD(lParam))
44# endif
45# ifndef GET_KEYSTATE_LPARAM
46# define GET_KEYSTATE_LPARAM(lParam) GET_FLAGS_LPARAM(lParam)
47# endif
48#endif
49
51
62
64 : m_useRTLExtensions(false), m_keyGrabber(nullptr)
65{
66 memset(keyLayout, 0, sizeof(keyLayout));
67 auto *app = static_cast<QGuiApplication *>(QGuiApplication::instance());
71}
72
74
75#ifndef LANG_PASHTO
76#define LANG_PASHTO 0x63
77#endif
78#ifndef LANG_SYRIAC
79#define LANG_SYRIAC 0x5a
80#endif
81#ifndef LANG_DIVEHI
82#define LANG_DIVEHI 0x65
83#endif
84#ifndef VK_OEM_PLUS
85#define VK_OEM_PLUS 0xBB
86#endif
87#ifndef VK_OEM_3
88#define VK_OEM_3 0xC0
89#endif
90
91// We not only need the scancode itself but also the extended bit of key messages. Thus we need
92// the additional bit when masking the scancode.
93enum { scancodeBitmask = 0x1ff };
94
95// Key recorder ------------------------------------------------------------------------[ start ] --
96struct KeyRecord {
97 KeyRecord(int c, int a, int s, const QString &t) : code(c), ascii(a), state(s), text(t) {}
99
100 int code;
101 int ascii;
102 int state;
104};
105
106// We need to record the pressed keys in order to decide, whether the key event is an autorepeat
107// event. As soon as its state changes, the chain of autorepeat events will be broken.
108static const int QT_MAX_KEY_RECORDINGS = 64; // User has LOTS of fingers...
110{
111 inline KeyRecord *findKey(int code, bool remove);
112 inline void storeKey(int code, int ascii, int state, const QString& text);
113 inline void clearKeys();
114
115 int nrecs = 0;
116 KeyRecord deleted_record; // A copy of last entry removed from records[]
118};
120
122{
125}
126
128{
129 KeyRecord *result = nullptr;
130 for (int i = 0; i < nrecs; ++i) {
131 if (records[i].code == code) {
132 if (remove) {
134 // Move rest down, and decrease count
135 while (i + 1 < nrecs) {
136 records[i] = records[i + 1];
137 ++i;
138 }
139 --nrecs;
141 } else {
142 result = &records[i];
143 }
144 break;
145 }
146 }
147 return result;
148}
149
150void KeyRecorder::storeKey(int code, int ascii, int state, const QString& text)
151{
153 "Internal KeyRecorder",
154 "Keyboard recorder buffer overflow, consider increasing QT_MAX_KEY_RECORDINGS");
155
157 qWarning("Qt: Internal keyboard buffer overflow");
158 return;
159 }
160 records[nrecs++] = KeyRecord(code,ascii,state,text);
161}
162
164{
165 nrecs = 0;
166}
167// Key recorder --------------------------------------------------------------------------[ end ] --
168
169
170// Key translation ---------------------------------------------------------------------[ start ] --
171// Meaning of values:
172// 0 = Character output key, needs keyboard driver mapping
173// Key_unknown = Unknown Virtual Key, no translation possible, ignore
174static const uint KeyTbl[] = { // Keyboard mapping table
175 // Dec | Hex | Windows Virtual key
176 Qt::Key_unknown, // 0 0x00
177 Qt::Key_unknown, // 1 0x01 VK_LBUTTON | Left mouse button
178 Qt::Key_unknown, // 2 0x02 VK_RBUTTON | Right mouse button
179 Qt::Key_Cancel, // 3 0x03 VK_CANCEL | Control-Break processing
180 Qt::Key_unknown, // 4 0x04 VK_MBUTTON | Middle mouse button
181 Qt::Key_unknown, // 5 0x05 VK_XBUTTON1 | X1 mouse button
182 Qt::Key_unknown, // 6 0x06 VK_XBUTTON2 | X2 mouse button
183 Qt::Key_unknown, // 7 0x07 -- unassigned --
184 Qt::Key_Backspace, // 8 0x08 VK_BACK | BackSpace key
185 Qt::Key_Tab, // 9 0x09 VK_TAB | Tab key
186 Qt::Key_unknown, // 10 0x0A -- reserved --
187 Qt::Key_unknown, // 11 0x0B -- reserved --
188 Qt::Key_Clear, // 12 0x0C VK_CLEAR | Clear key
189 Qt::Key_Return, // 13 0x0D VK_RETURN | Enter key
190 Qt::Key_unknown, // 14 0x0E -- unassigned --
191 Qt::Key_unknown, // 15 0x0F -- unassigned --
192 Qt::Key_Shift, // 16 0x10 VK_SHIFT | Shift key
193 Qt::Key_Control, // 17 0x11 VK_CONTROL | Ctrl key
194 Qt::Key_Alt, // 18 0x12 VK_MENU | Alt key
195 Qt::Key_Pause, // 19 0x13 VK_PAUSE | Pause key
196 Qt::Key_CapsLock, // 20 0x14 VK_CAPITAL | Caps-Lock
197 Qt::Key_unknown, // 21 0x15 VK_KANA / VK_HANGUL | IME Kana or Hangul mode
198 Qt::Key_unknown, // 22 0x16 -- unassigned --
199 Qt::Key_unknown, // 23 0x17 VK_JUNJA | IME Junja mode
200 Qt::Key_unknown, // 24 0x18 VK_FINAL | IME final mode
201 Qt::Key_unknown, // 25 0x19 VK_HANJA / VK_KANJI | IME Hanja or Kanji mode
202 Qt::Key_unknown, // 26 0x1A -- unassigned --
203 Qt::Key_Escape, // 27 0x1B VK_ESCAPE | Esc key
204 Qt::Key_unknown, // 28 0x1C VK_CONVERT | IME convert
205 Qt::Key_unknown, // 29 0x1D VK_NONCONVERT | IME non-convert
206 Qt::Key_unknown, // 30 0x1E VK_ACCEPT | IME accept
207 Qt::Key_Mode_switch,// 31 0x1F VK_MODECHANGE | IME mode change request
208 Qt::Key_Space, // 32 0x20 VK_SPACE | Spacebar
209 Qt::Key_PageUp, // 33 0x21 VK_PRIOR | Page Up key
210 Qt::Key_PageDown, // 34 0x22 VK_NEXT | Page Down key
211 Qt::Key_End, // 35 0x23 VK_END | End key
212 Qt::Key_Home, // 36 0x24 VK_HOME | Home key
213 Qt::Key_Left, // 37 0x25 VK_LEFT | Left arrow key
214 Qt::Key_Up, // 38 0x26 VK_UP | Up arrow key
215 Qt::Key_Right, // 39 0x27 VK_RIGHT | Right arrow key
216 Qt::Key_Down, // 40 0x28 VK_DOWN | Down arrow key
217 Qt::Key_Select, // 41 0x29 VK_SELECT | Select key
218 Qt::Key_Printer, // 42 0x2A VK_PRINT | Print key
219 Qt::Key_Execute, // 43 0x2B VK_EXECUTE | Execute key
220 Qt::Key_Print, // 44 0x2C VK_SNAPSHOT | Print Screen key
221 Qt::Key_Insert, // 45 0x2D VK_INSERT | Ins key
222 Qt::Key_Delete, // 46 0x2E VK_DELETE | Del key
223 Qt::Key_Help, // 47 0x2F VK_HELP | Help key
224 0, // 48 0x30 (VK_0) | 0 key
225 0, // 49 0x31 (VK_1) | 1 key
226 0, // 50 0x32 (VK_2) | 2 key
227 0, // 51 0x33 (VK_3) | 3 key
228 0, // 52 0x34 (VK_4) | 4 key
229 0, // 53 0x35 (VK_5) | 5 key
230 0, // 54 0x36 (VK_6) | 6 key
231 0, // 55 0x37 (VK_7) | 7 key
232 0, // 56 0x38 (VK_8) | 8 key
233 0, // 57 0x39 (VK_9) | 9 key
234 Qt::Key_unknown, // 58 0x3A -- unassigned --
235 Qt::Key_unknown, // 59 0x3B -- unassigned --
236 Qt::Key_unknown, // 60 0x3C -- unassigned --
237 Qt::Key_unknown, // 61 0x3D -- unassigned --
238 Qt::Key_unknown, // 62 0x3E -- unassigned --
239 Qt::Key_unknown, // 63 0x3F -- unassigned --
240 Qt::Key_unknown, // 64 0x40 -- unassigned --
241 0, // 65 0x41 (VK_A) | A key
242 0, // 66 0x42 (VK_B) | B key
243 0, // 67 0x43 (VK_C) | C key
244 0, // 68 0x44 (VK_D) | D key
245 0, // 69 0x45 (VK_E) | E key
246 0, // 70 0x46 (VK_F) | F key
247 0, // 71 0x47 (VK_G) | G key
248 0, // 72 0x48 (VK_H) | H key
249 0, // 73 0x49 (VK_I) | I key
250 0, // 74 0x4A (VK_J) | J key
251 0, // 75 0x4B (VK_K) | K key
252 0, // 76 0x4C (VK_L) | L key
253 0, // 77 0x4D (VK_M) | M key
254 0, // 78 0x4E (VK_N) | N key
255 0, // 79 0x4F (VK_O) | O key
256 0, // 80 0x50 (VK_P) | P key
257 0, // 81 0x51 (VK_Q) | Q key
258 0, // 82 0x52 (VK_R) | R key
259 0, // 83 0x53 (VK_S) | S key
260 0, // 84 0x54 (VK_T) | T key
261 0, // 85 0x55 (VK_U) | U key
262 0, // 86 0x56 (VK_V) | V key
263 0, // 87 0x57 (VK_W) | W key
264 0, // 88 0x58 (VK_X) | X key
265 0, // 89 0x59 (VK_Y) | Y key
266 0, // 90 0x5A (VK_Z) | Z key
267 Qt::Key_Meta, // 91 0x5B VK_LWIN | Left Windows - MS Natural kbd
268 Qt::Key_Meta, // 92 0x5C VK_RWIN | Right Windows - MS Natural kbd
269 Qt::Key_Menu, // 93 0x5D VK_APPS | Application key-MS Natural kbd
270 Qt::Key_unknown, // 94 0x5E -- reserved --
271 Qt::Key_Sleep, // 95 0x5F VK_SLEEP
272 Qt::Key_0, // 96 0x60 VK_NUMPAD0 | Numeric keypad 0 key
273 Qt::Key_1, // 97 0x61 VK_NUMPAD1 | Numeric keypad 1 key
274 Qt::Key_2, // 98 0x62 VK_NUMPAD2 | Numeric keypad 2 key
275 Qt::Key_3, // 99 0x63 VK_NUMPAD3 | Numeric keypad 3 key
276 Qt::Key_4, // 100 0x64 VK_NUMPAD4 | Numeric keypad 4 key
277 Qt::Key_5, // 101 0x65 VK_NUMPAD5 | Numeric keypad 5 key
278 Qt::Key_6, // 102 0x66 VK_NUMPAD6 | Numeric keypad 6 key
279 Qt::Key_7, // 103 0x67 VK_NUMPAD7 | Numeric keypad 7 key
280 Qt::Key_8, // 104 0x68 VK_NUMPAD8 | Numeric keypad 8 key
281 Qt::Key_9, // 105 0x69 VK_NUMPAD9 | Numeric keypad 9 key
282 Qt::Key_Asterisk, // 106 0x6A VK_MULTIPLY | Multiply key
283 Qt::Key_Plus, // 107 0x6B VK_ADD | Add key
284 Qt::Key_unknown, // 108 0x6C VK_SEPARATOR | Separator key (locale-dependent)
285 Qt::Key_Minus, // 109 0x6D VK_SUBTRACT | Subtract key
286 Qt::Key_unknown, // 110 0x6E VK_DECIMAL | Decimal key (locale-dependent)
287 Qt::Key_Slash, // 111 0x6F VK_DIVIDE | Divide key
288 Qt::Key_F1, // 112 0x70 VK_F1 | F1 key
289 Qt::Key_F2, // 113 0x71 VK_F2 | F2 key
290 Qt::Key_F3, // 114 0x72 VK_F3 | F3 key
291 Qt::Key_F4, // 115 0x73 VK_F4 | F4 key
292 Qt::Key_F5, // 116 0x74 VK_F5 | F5 key
293 Qt::Key_F6, // 117 0x75 VK_F6 | F6 key
294 Qt::Key_F7, // 118 0x76 VK_F7 | F7 key
295 Qt::Key_F8, // 119 0x77 VK_F8 | F8 key
296 Qt::Key_F9, // 120 0x78 VK_F9 | F9 key
297 Qt::Key_F10, // 121 0x79 VK_F10 | F10 key
298 Qt::Key_F11, // 122 0x7A VK_F11 | F11 key
299 Qt::Key_F12, // 123 0x7B VK_F12 | F12 key
300 Qt::Key_F13, // 124 0x7C VK_F13 | F13 key
301 Qt::Key_F14, // 125 0x7D VK_F14 | F14 key
302 Qt::Key_F15, // 126 0x7E VK_F15 | F15 key
303 Qt::Key_F16, // 127 0x7F VK_F16 | F16 key
304 Qt::Key_F17, // 128 0x80 VK_F17 | F17 key
305 Qt::Key_F18, // 129 0x81 VK_F18 | F18 key
306 Qt::Key_F19, // 130 0x82 VK_F19 | F19 key
307 Qt::Key_F20, // 131 0x83 VK_F20 | F20 key
308 Qt::Key_F21, // 132 0x84 VK_F21 | F21 key
309 Qt::Key_F22, // 133 0x85 VK_F22 | F22 key
310 Qt::Key_F23, // 134 0x86 VK_F23 | F23 key
311 Qt::Key_F24, // 135 0x87 VK_F24 | F24 key
312 Qt::Key_unknown, // 136 0x88 -- unassigned --
313 Qt::Key_unknown, // 137 0x89 -- unassigned --
314 Qt::Key_unknown, // 138 0x8A -- unassigned --
315 Qt::Key_unknown, // 139 0x8B -- unassigned --
316 Qt::Key_unknown, // 140 0x8C -- unassigned --
317 Qt::Key_unknown, // 141 0x8D -- unassigned --
318 Qt::Key_unknown, // 142 0x8E -- unassigned --
319 Qt::Key_unknown, // 143 0x8F -- unassigned --
320 Qt::Key_NumLock, // 144 0x90 VK_NUMLOCK | Num Lock key
321 Qt::Key_ScrollLock, // 145 0x91 VK_SCROLL | Scroll Lock key
322 // Fujitsu/OASYS kbd --------------------
323 0, //Qt::Key_Jisho, // 146 0x92 VK_OEM_FJ_JISHO | 'Dictionary' key /
324 // VK_OEM_NEC_EQUAL = key on numpad on NEC PC-9800 kbd
325 Qt::Key_Massyo, // 147 0x93 VK_OEM_FJ_MASSHOU | 'Unregister word' key
326 Qt::Key_Touroku, // 148 0x94 VK_OEM_FJ_TOUROKU | 'Register word' key
327 0, //Qt::Key_Oyayubi_Left,//149 0x95 VK_OEM_FJ_LOYA | 'Left OYAYUBI' key
328 0, //Qt::Key_Oyayubi_Right,//150 0x96 VK_OEM_FJ_ROYA | 'Right OYAYUBI' key
329 Qt::Key_unknown, // 151 0x97 -- unassigned --
330 Qt::Key_unknown, // 152 0x98 -- unassigned --
331 Qt::Key_unknown, // 153 0x99 -- unassigned --
332 Qt::Key_unknown, // 154 0x9A -- unassigned --
333 Qt::Key_unknown, // 155 0x9B -- unassigned --
334 Qt::Key_unknown, // 156 0x9C -- unassigned --
335 Qt::Key_unknown, // 157 0x9D -- unassigned --
336 Qt::Key_unknown, // 158 0x9E -- unassigned --
337 Qt::Key_unknown, // 159 0x9F -- unassigned --
338 Qt::Key_Shift, // 160 0xA0 VK_LSHIFT | Left Shift key
339 Qt::Key_Shift, // 161 0xA1 VK_RSHIFT | Right Shift key
340 Qt::Key_Control, // 162 0xA2 VK_LCONTROL | Left Ctrl key
341 Qt::Key_Control, // 163 0xA3 VK_RCONTROL | Right Ctrl key
342 Qt::Key_Alt, // 164 0xA4 VK_LMENU | Left Menu key
343 Qt::Key_Alt, // 165 0xA5 VK_RMENU | Right Menu key
344 Qt::Key_Back, // 166 0xA6 VK_BROWSER_BACK | Browser Back key
345 Qt::Key_Forward, // 167 0xA7 VK_BROWSER_FORWARD | Browser Forward key
346 Qt::Key_Refresh, // 168 0xA8 VK_BROWSER_REFRESH | Browser Refresh key
347 Qt::Key_Stop, // 169 0xA9 VK_BROWSER_STOP | Browser Stop key
348 Qt::Key_Search, // 170 0xAA VK_BROWSER_SEARCH | Browser Search key
349 Qt::Key_Favorites, // 171 0xAB VK_BROWSER_FAVORITES| Browser Favorites key
350 Qt::Key_HomePage, // 172 0xAC VK_BROWSER_HOME | Browser Start and Home key
351 Qt::Key_VolumeMute, // 173 0xAD VK_VOLUME_MUTE | Volume Mute key
352 Qt::Key_VolumeDown, // 174 0xAE VK_VOLUME_DOWN | Volume Down key
353 Qt::Key_VolumeUp, // 175 0xAF VK_VOLUME_UP | Volume Up key
354 Qt::Key_MediaNext, // 176 0xB0 VK_MEDIA_NEXT_TRACK | Next Track key
355 Qt::Key_MediaPrevious, //177 0xB1 VK_MEDIA_PREV_TRACK | Previous Track key
356 Qt::Key_MediaStop, // 178 0xB2 VK_MEDIA_STOP | Stop Media key
358 // 179 0xB3 VK_MEDIA_PLAY_PAUSE | Play/Pause Media key
359 Qt::Key_LaunchMail, // 180 0xB4 VK_LAUNCH_MAIL | Start Mail key
360 Qt::Key_LaunchMedia,// 181 0xB5 VK_LAUNCH_MEDIA_SELECT Select Media key
361 Qt::Key_Launch0, // 182 0xB6 VK_LAUNCH_APP1 | Start Application 1 key
362 Qt::Key_Launch1, // 183 0xB7 VK_LAUNCH_APP2 | Start Application 2 key
363 Qt::Key_unknown, // 184 0xB8 -- reserved --
364 Qt::Key_unknown, // 185 0xB9 -- reserved --
365 0, // 186 0xBA VK_OEM_1 | ';:' for US
366 0, // 187 0xBB VK_OEM_PLUS | '+' any country
367 0, // 188 0xBC VK_OEM_COMMA | ',' any country
368 0, // 189 0xBD VK_OEM_MINUS | '-' any country
369 0, // 190 0xBE VK_OEM_PERIOD | '.' any country
370 0, // 191 0xBF VK_OEM_2 | '/?' for US
371 0, // 192 0xC0 VK_OEM_3 | '`~' for US
372 Qt::Key_unknown, // 193 0xC1 -- reserved --
373 Qt::Key_unknown, // 194 0xC2 -- reserved --
374 Qt::Key_unknown, // 195 0xC3 -- reserved --
375 Qt::Key_unknown, // 196 0xC4 -- reserved --
376 Qt::Key_unknown, // 197 0xC5 -- reserved --
377 Qt::Key_unknown, // 198 0xC6 -- reserved --
378 Qt::Key_unknown, // 199 0xC7 -- reserved --
379 Qt::Key_unknown, // 200 0xC8 -- reserved --
380 Qt::Key_unknown, // 201 0xC9 -- reserved --
381 Qt::Key_unknown, // 202 0xCA -- reserved --
382 Qt::Key_unknown, // 203 0xCB -- reserved --
383 Qt::Key_unknown, // 204 0xCC -- reserved --
384 Qt::Key_unknown, // 205 0xCD -- reserved --
385 Qt::Key_unknown, // 206 0xCE -- reserved --
386 Qt::Key_unknown, // 207 0xCF -- reserved --
387 Qt::Key_unknown, // 208 0xD0 -- reserved --
388 Qt::Key_unknown, // 209 0xD1 -- reserved --
389 Qt::Key_unknown, // 210 0xD2 -- reserved --
390 Qt::Key_unknown, // 211 0xD3 -- reserved --
391 Qt::Key_unknown, // 212 0xD4 -- reserved --
392 Qt::Key_unknown, // 213 0xD5 -- reserved --
393 Qt::Key_unknown, // 214 0xD6 -- reserved --
394 Qt::Key_unknown, // 215 0xD7 -- reserved --
395 Qt::Key_unknown, // 216 0xD8 -- unassigned --
396 Qt::Key_unknown, // 217 0xD9 -- unassigned --
397 Qt::Key_unknown, // 218 0xDA -- unassigned --
398 0, // 219 0xDB VK_OEM_4 | '[{' for US
399 0, // 220 0xDC VK_OEM_5 | '\|' for US
400 0, // 221 0xDD VK_OEM_6 | ']}' for US
401 0, // 222 0xDE VK_OEM_7 | ''"' for US
402 0, // 223 0xDF VK_OEM_8
403 Qt::Key_unknown, // 224 0xE0 -- reserved --
404 Qt::Key_unknown, // 225 0xE1 VK_OEM_AX | 'AX' key on Japanese AX kbd
405 Qt::Key_unknown, // 226 0xE2 VK_OEM_102 | "<>" or "\|" on RT 102-key kbd
406 Qt::Key_unknown, // 227 0xE3 VK_ICO_HELP | Help key on ICO
407 Qt::Key_unknown, // 228 0xE4 VK_ICO_00 | 00 key on ICO
408 Qt::Key_unknown, // 229 0xE5 VK_PROCESSKEY | IME Process key
409 Qt::Key_unknown, // 230 0xE6 VK_ICO_CLEAR |
410 Qt::Key_unknown, // 231 0xE7 VK_PACKET | Unicode char as keystrokes
411 Qt::Key_unknown, // 232 0xE8 -- unassigned --
412 // Nokia/Ericsson definitions ---------------
413 Qt::Key_unknown, // 233 0xE9 VK_OEM_RESET
414 Qt::Key_unknown, // 234 0xEA VK_OEM_JUMP
415 Qt::Key_unknown, // 235 0xEB VK_OEM_PA1
416 Qt::Key_unknown, // 236 0xEC VK_OEM_PA2
417 Qt::Key_unknown, // 237 0xED VK_OEM_PA3
418 Qt::Key_unknown, // 238 0xEE VK_OEM_WSCTRL
419 Qt::Key_unknown, // 239 0xEF VK_OEM_CUSEL
420 Qt::Key_unknown, // 240 0xF0 VK_OEM_ATTN
421 Qt::Key_unknown, // 241 0xF1 VK_OEM_FINISH
422 Qt::Key_unknown, // 242 0xF2 VK_OEM_COPY
423 Qt::Key_unknown, // 243 0xF3 VK_OEM_AUTO
424 Qt::Key_unknown, // 244 0xF4 VK_OEM_ENLW
425 Qt::Key_unknown, // 245 0xF5 VK_OEM_BACKTAB
426 Qt::Key_unknown, // 246 0xF6 VK_ATTN | Attn key
427 Qt::Key_unknown, // 247 0xF7 VK_CRSEL | CrSel key
428 Qt::Key_unknown, // 248 0xF8 VK_EXSEL | ExSel key
429 Qt::Key_unknown, // 249 0xF9 VK_EREOF | Erase EOF key
430 Qt::Key_Play, // 250 0xFA VK_PLAY | Play key
431 Qt::Key_Zoom, // 251 0xFB VK_ZOOM | Zoom key
432 Qt::Key_unknown, // 252 0xFC VK_NONAME | Reserved
433 Qt::Key_unknown, // 253 0xFD VK_PA1 | PA1 key
434 Qt::Key_Clear, // 254 0xFE VK_OEM_CLEAR | Clear key
435 0
436};
437
438static const uint CmdTbl[] = { // Multimedia keys mapping table
439 // Dec | Hex | AppCommand
440 Qt::Key_unknown, // 0 0x00
441 Qt::Key_Back, // 1 0x01 APPCOMMAND_BROWSER_BACKWARD
442 Qt::Key_Forward, // 2 0x02 APPCOMMAND_BROWSER_FORWARD
443 Qt::Key_Refresh, // 3 0x03 APPCOMMAND_BROWSER_REFRESH
444 Qt::Key_Stop, // 4 0x04 APPCOMMAND_BROWSER_STOP
445 Qt::Key_Search, // 5 0x05 APPCOMMAND_BROWSER_SEARCH
446 Qt::Key_Favorites, // 6 0x06 APPCOMMAND_BROWSER_FAVORITES
447 Qt::Key_Home, // 7 0x07 APPCOMMAND_BROWSER_HOME
448 Qt::Key_VolumeMute, // 8 0x08 APPCOMMAND_VOLUME_MUTE
449 Qt::Key_VolumeDown, // 9 0x09 APPCOMMAND_VOLUME_DOWN
450 Qt::Key_VolumeUp, // 10 0x0a APPCOMMAND_VOLUME_UP
451 Qt::Key_MediaNext, // 11 0x0b APPCOMMAND_MEDIA_NEXTTRACK
452 Qt::Key_MediaPrevious, // 12 0x0c APPCOMMAND_MEDIA_PREVIOUSTRACK
453 Qt::Key_MediaStop, // 13 0x0d APPCOMMAND_MEDIA_STOP
454 Qt::Key_MediaTogglePlayPause, // 14 0x0e APPCOMMAND_MEDIA_PLAYPAUSE
455 Qt::Key_LaunchMail, // 15 0x0f APPCOMMAND_LAUNCH_MAIL
456 Qt::Key_LaunchMedia, // 16 0x10 APPCOMMAND_LAUNCH_MEDIA_SELECT
457 Qt::Key_Launch0, // 17 0x11 APPCOMMAND_LAUNCH_APP1
458 Qt::Key_Launch1, // 18 0x12 APPCOMMAND_LAUNCH_APP2
459 Qt::Key_BassDown, // 19 0x13 APPCOMMAND_BASS_DOWN
460 Qt::Key_BassBoost, // 20 0x14 APPCOMMAND_BASS_BOOST
461 Qt::Key_BassUp, // 21 0x15 APPCOMMAND_BASS_UP
462 Qt::Key_TrebleDown, // 22 0x16 APPCOMMAND_TREBLE_DOWN
463 Qt::Key_TrebleUp, // 23 0x17 APPCOMMAND_TREBLE_UP
464 Qt::Key_MicMute, // 24 0x18 APPCOMMAND_MICROPHONE_VOLUME_MUTE
465 Qt::Key_MicVolumeDown, // 25 0x19 APPCOMMAND_MICROPHONE_VOLUME_DOWN
466 Qt::Key_MicVolumeUp, // 26 0x1a APPCOMMAND_MICROPHONE_VOLUME_UP
467 Qt::Key_Help, // 27 0x1b APPCOMMAND_HELP
468 Qt::Key_Find, // 28 0x1c APPCOMMAND_FIND
469 Qt::Key_New, // 29 0x1d APPCOMMAND_NEW
470 Qt::Key_Open, // 30 0x1e APPCOMMAND_OPEN
471 Qt::Key_Close, // 31 0x1f APPCOMMAND_CLOSE
472 Qt::Key_Save, // 32 0x20 APPCOMMAND_SAVE
473 Qt::Key_Printer, // 33 0x21 APPCOMMAND_PRINT
474 Qt::Key_Undo, // 34 0x22 APPCOMMAND_UNDO
475 Qt::Key_Redo, // 35 0x23 APPCOMMAND_REDO
476 Qt::Key_Copy, // 36 0x24 APPCOMMAND_COPY
477 Qt::Key_Cut, // 37 0x25 APPCOMMAND_CUT
478 Qt::Key_Paste, // 38 0x26 APPCOMMAND_PASTE
479 Qt::Key_Reply, // 39 0x27 APPCOMMAND_REPLY_TO_MAIL
480 Qt::Key_MailForward, // 40 0x28 APPCOMMAND_FORWARD_MAIL
481 Qt::Key_Send, // 41 0x29 APPCOMMAND_SEND_MAIL
482 Qt::Key_Spell, // 42 0x2a APPCOMMAND_SPELL_CHECK
483 Qt::Key_unknown, // 43 0x2b APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE
484 Qt::Key_unknown, // 44 0x2c APPCOMMAND_MIC_ON_OFF_TOGGLE
485 Qt::Key_unknown, // 45 0x2d APPCOMMAND_CORRECTION_LIST
486 Qt::Key_MediaPlay, // 46 0x2e APPCOMMAND_MEDIA_PLAY
487 Qt::Key_MediaPause, // 47 0x2f APPCOMMAND_MEDIA_PAUSE
488 Qt::Key_MediaRecord, // 48 0x30 APPCOMMAND_MEDIA_RECORD
489 Qt::Key_AudioForward, // 49 0x31 APPCOMMAND_MEDIA_FAST_FORWARD
490 Qt::Key_AudioRewind, // 50 0x32 APPCOMMAND_MEDIA_REWIND
491 Qt::Key_ChannelDown, // 51 0x33 APPCOMMAND_MEDIA_CHANNEL_DOWN
492 Qt::Key_ChannelUp // 52 0x34 APPCOMMAND_MEDIA_CHANNEL_UP
493};
494
495// Possible modifier states.
496// NOTE: The order of these states match the order in QWindowsKeyMapper::updatePossibleKeyCodes()!
497static const Qt::KeyboardModifiers ModsTbl[] = {
498 Qt::NoModifier, // 0
502 Qt::AltModifier, // 4
506 Qt::NoModifier, // Fall-back to raw Key_*
507};
508static const size_t NumMods = sizeof ModsTbl / sizeof *ModsTbl;
509static_assert((NumMods == KeyboardLayoutItem::NumQtKeys));
510
511#ifndef QT_NO_DEBUG_STREAM
513{
514 QDebugStateSaver saver(d);
515 d.nospace();
516 d << "KeyboardLayoutItem(";
517 if (k.exists) {
518 for (size_t i = 0; i < NumMods; ++i) {
519 if (const quint32 qtKey = k.qtKey[i]) {
520 d << '[' << i << ' ';
522 d << ' ' << Qt::hex << Qt::showbase << qtKey << Qt::dec << Qt::noshowbase << ' ';
524 if (qtKey >= 32 && qtKey < 128)
525 d << " '" << char(qtKey) << '\'';
526 if (k.deadkeys & (1<<i))
527 d << " deadkey";
528 d << "] ";
529 }
530 }
531 }
532 d << ')';
533 return d;
534}
535
536// Helpers to format a list of int as Qt key sequence
538{
539public:
540 explicit formatKeys(const QList<int> &keys) : m_keys(keys) {}
541
542private:
543 friend QDebug operator<<(QDebug d, const formatKeys &keys);
544 const QList<int> &m_keys;
545};
546
548{
549 QDebugStateSaver saver(d);
550 d.nospace();
551 d << '(';
552 for (int i =0, size = k.m_keys.size(); i < size; ++i) {
553 if (i)
554 d << ", ";
555 d << QKeySequence(k.m_keys.at(i));
556 }
557 d << ')';
558 return d;
559}
560#else // !QT_NO_DEBUG_STREAM
561static int formatKeys(const QList<int> &) { return 0; }
562#endif // QT_NO_DEBUG_STREAM
563
568{
569 return KeyTbl[keyCode];
570}
571
572// Translate a VK into a Qt key code, or unicode character
573static inline quint32 toKeyOrUnicode(quint32 vk, quint32 scancode, unsigned char *kbdBuffer, bool *isDeadkey = nullptr)
574{
575 Q_ASSERT(vk > 0 && vk < 256);
576 quint32 code = 0;
577 QChar unicodeBuffer[5];
578 int res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0);
579 // When Ctrl modifier is used ToUnicode does not return correct values. In order to assign the
580 // right key the control modifier is removed for just that function if the previous call failed.
581 if (res == 0 && kbdBuffer[VK_CONTROL]) {
582 const unsigned char controlState = kbdBuffer[VK_CONTROL];
583 kbdBuffer[VK_CONTROL] = 0;
584 res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0);
585 kbdBuffer[VK_CONTROL] = controlState;
586 }
587 if (res)
588 code = unicodeBuffer[0].toUpper().unicode();
589
590 // Qt::Key_*'s are not encoded below 0x20, so try again, and DEL keys (0x7f) is encoded with a
591 // proper Qt::Key_ code
592 if (code < 0x20 || code == 0x7f) // Handles res==0 too
593 code = winceKeyBend(vk);
594
595 if (isDeadkey)
596 *isDeadkey = (res == -1);
597
598 return code == Qt::Key_unknown ? 0 : code;
599}
600
601static inline int asciiToKeycode(char a, int state)
602{
604 if ((state & Qt::ControlModifier) != 0) {
605 if (a >= 0 && a <= 31) // Ctrl+@..Ctrl+A..CTRL+Z..Ctrl+_
606 a += '@'; // to @..A..Z.._
607 }
608 return a & 0xff;
609}
610
611// Key translation -----------------------------------------------------------------------[ end ]---
612
613
614// Keyboard map private ----------------------------------------------------------------[ start ]---
615
616void QWindowsKeyMapper::deleteLayouts()
617{
618 for (KeyboardLayoutItem &k : keyLayout)
619 k.exists = false;
620}
621
623{
624 deleteLayouts();
625
626 /* MAKELCID()'s first argument is a WORD, and GetKeyboardLayout()
627 * returns a DWORD. */
628
629 LCID newLCID = MAKELCID(quintptr(GetKeyboardLayout(0)), SORT_DEFAULT);
630// keyboardInputLocale = qt_localeFromLCID(newLCID);
631
632 bool bidi = false;
633 wchar_t LCIDFontSig[16];
634 if (GetLocaleInfo(newLCID, LOCALE_FONTSIGNATURE, LCIDFontSig, sizeof(LCIDFontSig) / sizeof(wchar_t))
635 && (LCIDFontSig[7] & wchar_t(0x0800)))
636 bidi = true;
637
638 keyboardInputDirection = bidi ? Qt::RightToLeft : Qt::LeftToRight;
639 m_seenAltGr = false;
640}
641
642// Helper function that is used when obtaining the list of characters that can be produced by one key and
643// every possible combination of modifiers
644inline void setKbdState(unsigned char *kbd, bool shift, bool ctrl, bool alt)
645{
646 kbd[VK_LSHIFT ] = (shift ? 0x80 : 0);
647 kbd[VK_SHIFT ] = (shift ? 0x80 : 0);
648 kbd[VK_LCONTROL] = (ctrl ? 0x80 : 0);
649 kbd[VK_CONTROL ] = (ctrl ? 0x80 : 0);
650 kbd[VK_RMENU ] = (alt ? 0x80 : 0);
651 kbd[VK_MENU ] = (alt ? 0x80 : 0);
652}
653
654// Adds the msg's key to keyLayout if it is not yet present there
655void QWindowsKeyMapper::updateKeyMap(const MSG &msg)
656{
657 unsigned char kbdBuffer[256]; // Will hold the complete keyboard state
658 GetKeyboardState(kbdBuffer);
659 const quint32 scancode = (msg.lParam >> 16) & scancodeBitmask;
660 updatePossibleKeyCodes(kbdBuffer, scancode, quint32(msg.wParam));
661}
662
663// Fills keyLayout for that vk_key. Values are all characters one can type using that key
664// (in connection with every combination of modifiers) and whether these "characters" are
665// dead keys.
666void QWindowsKeyMapper::updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 scancode,
667 quint32 vk_key)
668{
669 if (!vk_key || (keyLayout[vk_key].exists && !keyLayout[vk_key].dirty))
670 return;
671
672 // Copy keyboard state, so we can modify and query output for each possible permutation
673 unsigned char buffer[256];
674 memcpy(buffer, kbdBuffer, sizeof(buffer));
675 // Always 0, as Windows doesn't treat these as modifiers;
676 buffer[VK_LWIN ] = 0;
677 buffer[VK_RWIN ] = 0;
678 buffer[VK_CAPITAL ] = 0;
679 buffer[VK_NUMLOCK ] = 0;
680 buffer[VK_SCROLL ] = 0;
681 // Always 0, since we'll only change the other versions
682 buffer[VK_RSHIFT ] = 0;
683 buffer[VK_RCONTROL] = 0;
684 buffer[VK_LMENU ] = 0; // Use right Alt, since left Ctrl + right Alt is considered AltGraph
685
686 // keyLayout contains the actual characters which can be written using the vk_key together with the
687 // different modifiers. '2' together with shift will for example cause the character
688 // to be @ for a US key layout (thus keyLayout[vk_key].qtKey[1] will be @). In addition to that
689 // it stores whether the resulting key is a dead key as these keys have to be handled later.
690 bool isDeadKey = false;
691 keyLayout[vk_key].deadkeys = 0;
692 keyLayout[vk_key].dirty = false;
693 keyLayout[vk_key].exists = true;
694 setKbdState(buffer, false, false, false);
695 keyLayout[vk_key].qtKey[0] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
696 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x01 : 0;
697 setKbdState(buffer, true, false, false);
698 keyLayout[vk_key].qtKey[1] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
699 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x02 : 0;
700 setKbdState(buffer, false, true, false);
701 keyLayout[vk_key].qtKey[2] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
702 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x04 : 0;
703 setKbdState(buffer, true, true, false);
704 keyLayout[vk_key].qtKey[3] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
705 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x08 : 0;
706 setKbdState(buffer, false, false, true);
707 keyLayout[vk_key].qtKey[4] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
708 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x10 : 0;
709 setKbdState(buffer, true, false, true);
710 keyLayout[vk_key].qtKey[5] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
711 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x20 : 0;
712 setKbdState(buffer, false, true, true);
713 keyLayout[vk_key].qtKey[6] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
714 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x40 : 0;
715 setKbdState(buffer, true, true, true);
716 keyLayout[vk_key].qtKey[7] = toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
717 keyLayout[vk_key].deadkeys |= isDeadKey ? 0x80 : 0;
718 // Add a fall back key for layouts which don't do composition and show non-latin1 characters
719 quint32 fallbackKey = winceKeyBend(vk_key);
720 if (!fallbackKey || fallbackKey == Qt::Key_unknown) {
721 fallbackKey = 0;
722 if (vk_key != keyLayout[vk_key].qtKey[0] && vk_key != keyLayout[vk_key].qtKey[1]
723 && vk_key < 0x5B && vk_key > 0x2F)
724 fallbackKey = vk_key;
725 }
726 keyLayout[vk_key].qtKey[8] = fallbackKey;
727
728 // If one of the values inserted into the keyLayout above, can be considered a dead key, we have
729 // to run the workaround below.
730 if (keyLayout[vk_key].deadkeys) {
731 // Push a Space, then the original key through the low-level ToAscii functions.
732 // We do this because these functions (ToAscii / ToUnicode) will alter the internal state of
733 // the keyboard driver By doing the following, we set the keyboard driver state back to what
734 // it was before we wrecked it with the code above.
735 // We need to push the space with an empty keystate map, since the driver checks the map for
736 // transitions in modifiers, so this helps us capture all possible deadkeys.
737 unsigned char emptyBuffer[256];
738 memset(emptyBuffer, 0, sizeof(emptyBuffer));
739 ::ToAscii(VK_SPACE, 0, emptyBuffer, reinterpret_cast<LPWORD>(&buffer), 0);
740 ::ToAscii(vk_key, scancode, kbdBuffer, reinterpret_cast<LPWORD>(&buffer), 0);
741 }
742 qCDebug(lcQpaEvents) << __FUNCTION__ << "for virtual key="
743 << Qt::hex << Qt::showbase << vk_key << Qt::dec << Qt::noshowbase << keyLayout[vk_key];
744}
745
746static inline QString messageKeyText(const MSG &msg)
747{
748 const QChar ch = QChar(ushort(msg.wParam));
749 return ch.isNull() ? QString() : QString(ch);
750}
751
752[[nodiscard]] static inline int getTitleBarHeight(const HWND hwnd)
753{
754 const UINT dpi = GetDpiForWindow(hwnd);
755 const int captionHeight = GetSystemMetricsForDpi(SM_CYCAPTION, dpi);
756 if (IsZoomed(hwnd))
757 return captionHeight;
758 // The frame height should also be taken into account if the window
759 // is not maximized.
760 const int frameHeight = GetSystemMetricsForDpi(SM_CYSIZEFRAME, dpi)
761 + GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);
762 return captionHeight + frameHeight;
763}
764
765[[nodiscard]] static inline bool isSystemMenuOffsetNeeded(const Qt::WindowFlags flags)
766{
767 static constexpr const Qt::WindowFlags titleBarHints =
769 return (flags & Qt::WindowSystemMenuHint) && (flags & Qt::WindowTitleHint) && !(flags & titleBarHints)
771}
772
774{
776 HWND topLevelHwnd = QWindowsWindow::handleOf(topLevel);
777 HMENU menu = GetSystemMenu(topLevelHwnd, FALSE);
778 if (!menu)
779 return; // no menu for this window
780
781#define enabled (MF_BYCOMMAND | MFS_ENABLED)
782#define disabled (MF_BYCOMMAND | MFS_GRAYED)
783
784 EnableMenuItem(menu, SC_MINIMIZE, (topLevel->flags() & Qt::WindowMinimizeButtonHint) ? enabled : disabled);
785 const bool maximized = IsZoomed(topLevelHwnd);
786
787 EnableMenuItem(menu, SC_MAXIMIZE, !(topLevel->flags() & Qt::WindowMaximizeButtonHint) || maximized ? disabled : enabled);
788
789 // We should _not_ check with the setFixedSize(x,y) case here, since Windows is not able to check
790 // this and our menu here would be out-of-sync with the menu produced by mouse-click on the
791 // System Menu, or right-click on the title bar.
792 EnableMenuItem(menu, SC_SIZE, (topLevel->flags() & Qt::MSWindowsFixedSizeDialogHint) || maximized ? disabled : enabled);
793 EnableMenuItem(menu, SC_MOVE, maximized ? disabled : enabled);
794 EnableMenuItem(menu, SC_CLOSE, enabled);
795 EnableMenuItem(menu, SC_RESTORE, maximized ? enabled : disabled);
796
797 // Highlight the first entry in the menu, this is what native Win32 applications usually do.
798 HiliteMenuItem(topLevelHwnd, menu, SC_RESTORE, MF_BYCOMMAND | MFS_HILITE);
799
800 // Set bold on close menu item
801 SetMenuDefaultItem(menu, SC_CLOSE, FALSE);
802
803#undef enabled
804#undef disabled
805
806 const QPoint pos = QHighDpi::toNativePixels(topLevel->geometry().topLeft(), topLevel);
807 const int titleBarOffset = isSystemMenuOffsetNeeded(topLevel->flags()) ? getTitleBarHeight(topLevelHwnd) : 0;
808 const int ret = TrackPopupMenuEx(menu,
809 TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD,
810 pos.x(), pos.y() + titleBarOffset,
811 topLevelHwnd,
812 nullptr);
813
814 // Remove the highlight of the restore menu item, otherwise when the user right-clicks
815 // on the title bar, the popuped system menu will also highlight the restore item, which
816 // is not appropriate, it should only be highlighted if the menu is brought up by keyboard.
817 HiliteMenuItem(topLevelHwnd, menu, SC_RESTORE, MF_BYCOMMAND | MFS_UNHILITE);
818
819 if (ret)
820 qWindowsWndProc(topLevelHwnd, WM_SYSCOMMAND, WPARAM(ret), 0);
821}
822
823static inline void sendExtendedPressRelease(QWindow *w, int k,
824 Qt::KeyboardModifiers mods,
825 quint32 nativeScanCode,
826 quint32 nativeVirtualKey,
827 quint32 nativeModifiers,
828 const QString & text = QString(),
829 bool autorep = false,
830 ushort count = 1)
831{
832 QWindowSystemInterface::handleExtendedKeyEvent(w, QEvent::KeyPress, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
833 QWindowSystemInterface::handleExtendedKeyEvent(w, QEvent::KeyRelease, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
834}
835
841 const MSG &msg, LRESULT *result)
842{
843 *result = 0;
844
845 // Reset layout map when system keyboard layout is changed
846 if (msg.message == WM_INPUTLANGCHANGE) {
848 return true;
849 }
850
851#if defined(WM_APPCOMMAND)
852 if (msg.message == WM_APPCOMMAND)
853 return translateMultimediaKeyEventInternal(widget, msg);
854#endif
855
856 // WM_(IME_)CHAR messages already contain the character in question so there is
857 // no need to fiddle with our key map. In any other case add this key to the
858 // keymap if it is not present yet.
859 if (msg.message != WM_CHAR && msg.message != WM_IME_CHAR)
860 updateKeyMap(msg);
861
862 MSG peekedMsg;
863 // consume dead chars?(for example, typing '`','a' resulting in a-accent).
864 if (PeekMessage(&peekedMsg, hwnd, 0, 0, PM_NOREMOVE) && peekedMsg.message == WM_DEADCHAR)
865 return true;
866
867 return translateKeyEventInternal(widget, msg, false, result);
868}
869
870bool QWindowsKeyMapper::translateMultimediaKeyEventInternal(QWindow *window, const MSG &msg)
871{
872#if defined(WM_APPCOMMAND)
873 const int cmd = GET_APPCOMMAND_LPARAM(msg.lParam);
874 // QTBUG-57198, do not send mouse-synthesized commands as key events in addition
875 bool skipPressRelease = false;
876 switch (GET_DEVICE_LPARAM(msg.lParam)) {
877 case FAPPCOMMAND_MOUSE:
878 return false;
879 case FAPPCOMMAND_KEY:
880 // QTBUG-62838, use WM_KEYDOWN/WM_KEYUP for commands that are reflected
881 // in VK(s) like VK_MEDIA_NEXT_TRACK, to get correct codes and autorepeat.
882 // Don't do that for APPCOMMAND_BROWSER_HOME as that one does not trigger two events.
883 if (cmd != APPCOMMAND_BROWSER_HOME)
884 skipPressRelease = true;
885 break;
886 }
887
888 const int dwKeys = GET_KEYSTATE_LPARAM(msg.lParam);
889 int state = 0;
890 state |= (dwKeys & MK_SHIFT ? int(Qt::ShiftModifier) : 0);
891 state |= (dwKeys & MK_CONTROL ? int(Qt::ControlModifier) : 0);
892
893 QWindow *receiver = m_keyGrabber ? m_keyGrabber : window;
894
895 if (cmd < 0 || cmd > 52)
896 return false;
897
898 const int qtKey = int(CmdTbl[cmd]);
899 if (!skipPressRelease)
901 // QTBUG-43343: Make sure to return false if Qt does not handle the key, otherwise,
902 // the keys are not passed to the active media player.
903# if QT_CONFIG(shortcut)
904 const QKeySequence sequence(Qt::Modifier(state) | Qt::Key(qtKey));
905 return QGuiApplicationPrivate::instance()->shortcutMap.hasShortcutForKeySequence(sequence);
906# else
907 return false;
908# endif
909#else
910 Q_UNREACHABLE();
911 return false;
912#endif
913}
914
915// QTBUG-69317: Check for AltGr found on some keyboards
916// which is a sequence of left Ctrl (SYSKEY) + right Menu (Alt).
917static bool isAltGr(MSG *msg)
918{
919 enum : LONG_PTR { RightFlag = 0x1000000 };
920 if (msg->wParam != VK_CONTROL || (msg->lParam & RightFlag) != 0
921 || (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYUP)) {
922 return false;
923 }
924 const UINT expectedMessage = msg->message == WM_SYSKEYUP
925 ? WM_KEYUP : msg->message;
926 MSG peekedMsg;
927 if (PeekMessage(&peekedMsg, msg->hwnd, 0, 0, PM_NOREMOVE) == FALSE
928 || peekedMsg.message != expectedMessage || peekedMsg.wParam != VK_MENU
929 || (peekedMsg.lParam & RightFlag) == 0) {
930 return false;
931 }
932 *msg = peekedMsg;
933 PeekMessage(&peekedMsg, msg->hwnd, 0, 0, PM_REMOVE);
934 return true;
935}
936
937bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
938 bool /* grab */, LRESULT *lResult)
939{
940 const bool altGr = m_detectAltGrModifier && isAltGr(&msg);
941 if (altGr)
942 m_seenAltGr = true;
943 const UINT msgType = msg.message;
944
945 const quint32 scancode = (msg.lParam >> 16) & scancodeBitmask;
946 auto vk_key = quint32(msg.wParam);
947 quint32 nModifiers = 0;
948
949 QWindow *receiver = m_keyGrabber ? m_keyGrabber : window;
950
951 // Map native modifiers to some bit representation
952 nModifiers |= (GetKeyState(VK_LSHIFT ) & 0x80 ? ShiftLeft : 0);
953 nModifiers |= (GetKeyState(VK_RSHIFT ) & 0x80 ? ShiftRight : 0);
954 nModifiers |= (GetKeyState(VK_LCONTROL) & 0x80 ? ControlLeft : 0);
955 nModifiers |= (GetKeyState(VK_RCONTROL) & 0x80 ? ControlRight : 0);
956 nModifiers |= (GetKeyState(VK_LMENU ) & 0x80 ? AltLeft : 0);
957 nModifiers |= (GetKeyState(VK_RMENU ) & 0x80 ? AltRight : 0);
958 nModifiers |= (GetKeyState(VK_LWIN ) & 0x80 ? MetaLeft : 0);
959 nModifiers |= (GetKeyState(VK_RWIN ) & 0x80 ? MetaRight : 0);
960 // Add Lock keys to the same bits
961 nModifiers |= (GetKeyState(VK_CAPITAL ) & 0x01 ? CapsLock : 0);
962 nModifiers |= (GetKeyState(VK_NUMLOCK ) & 0x01 ? NumLock : 0);
963 nModifiers |= (GetKeyState(VK_SCROLL ) & 0x01 ? ScrollLock : 0);
964
965 if (msg.lParam & ExtendedKey)
966 nModifiers |= msg.lParam & ExtendedKey;
967
968 // Get the modifier states (may be altered later, depending on key code)
969 int state = 0;
970 state |= (nModifiers & ShiftAny ? int(Qt::ShiftModifier) : 0);
971 state |= (nModifiers & AltLeft ? int(Qt::AltModifier) : 0);
972 if ((nModifiers & AltRight) != 0)
974 if ((nModifiers & ControlAny) != 0 && (state & Qt::GroupSwitchModifier) == 0)
976 state |= (nModifiers & MetaAny ? int(Qt::MetaModifier) : 0);
977 // A multi-character key or a Input method character
978 // not found by our look-ahead
979 if (msgType == WM_CHAR || msgType == WM_IME_CHAR) {
980 sendExtendedPressRelease(receiver, 0, Qt::KeyboardModifier(state), scancode, vk_key, nModifiers, messageKeyText(msg), false);
981 return true;
982 }
983
984 // Enable Alt accelerators ("&File") on menus
985 if (msgType == WM_SYSKEYDOWN && (nModifiers & AltAny) != 0 && GetMenu(msg.hwnd) != nullptr)
986 return false;
987 if (msgType == WM_SYSKEYUP && nModifiers == 0 && GetMenu(msg.hwnd) != nullptr)
988 return false;
989
990 bool result = false;
991 // handle Directionality changes (BiDi) with RTL extensions
992 if (m_useRTLExtensions) {
993 static int dirStatus = 0;
994 if (!dirStatus && state == Qt::ControlModifier
995 && msg.wParam == VK_CONTROL
996 && msgType == WM_KEYDOWN) {
997 if (GetKeyState(VK_LCONTROL) < 0)
998 dirStatus = VK_LCONTROL;
999 else if (GetKeyState(VK_RCONTROL) < 0)
1000 dirStatus = VK_RCONTROL;
1001 } else if (dirStatus) {
1002 if (msgType == WM_KEYDOWN) {
1003 if (msg.wParam == VK_SHIFT) {
1004 if (dirStatus == VK_LCONTROL && GetKeyState(VK_LSHIFT) < 0)
1005 dirStatus = VK_LSHIFT;
1006 else if (dirStatus == VK_RCONTROL && GetKeyState(VK_RSHIFT) < 0)
1007 dirStatus = VK_RSHIFT;
1008 } else {
1009 dirStatus = 0;
1010 }
1011 } else if (msgType == WM_KEYUP) {
1012 if (dirStatus == VK_LSHIFT
1013 && ((msg.wParam == VK_SHIFT && GetKeyState(VK_LCONTROL))
1014 || (msg.wParam == VK_CONTROL && GetKeyState(VK_LSHIFT)))) {
1016 scancode, vk_key, nModifiers, QString(), false);
1017 result = true;
1018 dirStatus = 0;
1019 } else if (dirStatus == VK_RSHIFT
1020 && ( (msg.wParam == VK_SHIFT && GetKeyState(VK_RCONTROL))
1021 || (msg.wParam == VK_CONTROL && GetKeyState(VK_RSHIFT)))) {
1023 scancode, vk_key, nModifiers, QString(), false);
1024 result = true;
1025 dirStatus = 0;
1026 } else {
1027 dirStatus = 0;
1028 }
1029 } else {
1030 dirStatus = 0;
1031 }
1032 }
1033 } // RTL
1034
1035 // IME will process these keys, so simply return
1036 if (msg.wParam == VK_PROCESSKEY)
1037 return true;
1038
1039 // Ignore invalid virtual keycodes (see bugs 127424, QTBUG-3630)
1040 if (msg.wParam == 0 || msg.wParam == 0xFF)
1041 return true;
1042
1043 // Translate VK_* (native) -> Key_* (Qt) keys
1044 int modifiersIndex = 0;
1045 modifiersIndex |= (nModifiers & ShiftAny ? 0x1 : 0);
1046 modifiersIndex |= (nModifiers & ControlAny ? 0x2 : 0);
1047 modifiersIndex |= (nModifiers & AltAny ? 0x4 : 0);
1048
1049 // Note: For the resulting key, AltGr is equivalent to Alt + Ctrl (as
1050 // opposed to Linux); hence no entry in KeyboardLayoutItem is required
1051 int code = keyLayout[vk_key].qtKey[modifiersIndex];
1052
1053 // If the bit 24 of lParm is set you received a enter,
1054 // otherwise a Return. (This is the extended key bit)
1055 if ((code == Qt::Key_Return) && (msg.lParam & 0x1000000))
1057 else if (altGr)
1059
1060 // Invert state logic:
1061 // If the key actually pressed is a modifier key, then we remove its modifier key from the
1062 // state, since a modifier-key can't have itself as a modifier
1063 if (code == Qt::Key_Control)
1065 else if (code == Qt::Key_Shift)
1067 else if (code == Qt::Key_Alt)
1069 else if (code == Qt::Key_AltGr)
1071
1072 // All cursor keys without extended bit
1073 if (!(msg.lParam & 0x1000000)) {
1074 switch (code) {
1075 case Qt::Key_Left:
1076 case Qt::Key_Right:
1077 case Qt::Key_Up:
1078 case Qt::Key_Down:
1079 case Qt::Key_PageUp:
1080 case Qt::Key_PageDown:
1081 case Qt::Key_Home:
1082 case Qt::Key_End:
1083 case Qt::Key_Insert:
1084 case Qt::Key_Delete:
1085 case Qt::Key_Asterisk:
1086 case Qt::Key_Plus:
1087 case Qt::Key_Minus:
1088 case Qt::Key_Period:
1089 case Qt::Key_Comma:
1090 case Qt::Key_0:
1091 case Qt::Key_1:
1092 case Qt::Key_2:
1093 case Qt::Key_3:
1094 case Qt::Key_4:
1095 case Qt::Key_5:
1096 case Qt::Key_6:
1097 case Qt::Key_7:
1098 case Qt::Key_8:
1099 case Qt::Key_9:
1100 state |= ((msg.wParam >= '0' && msg.wParam <= '9')
1101 || (msg.wParam >= VK_OEM_PLUS && msg.wParam <= VK_OEM_3))
1102 ? 0 : int(Qt::KeypadModifier);
1103 Q_FALLTHROUGH();
1104 default:
1105 if (uint(msg.lParam) == 0x004c0001 || uint(msg.lParam) == 0xc04c0001)
1107 break;
1108 }
1109 }
1110 // Other keys with with extended bit
1111 else {
1112 switch (code) {
1113 case Qt::Key_Enter:
1114 case Qt::Key_Slash:
1115 case Qt::Key_NumLock:
1117 break;
1118 default:
1119 break;
1120 }
1121 }
1122
1123 // KEYDOWN ---------------------------------------------------------------------------------
1124 if (msgType == WM_KEYDOWN || msgType == WM_IME_KEYDOWN || msgType == WM_SYSKEYDOWN) {
1125 // Get the last record of this key press, so we can validate the current state
1126 // The record is not removed from the list
1127 KeyRecord *rec = key_recorder.findKey(int(msg.wParam), false);
1128
1129 // If rec's state doesn't match the current state, something has changed behind our back
1130 // (Consumed by modal widget is one possibility) So, remove the record from the list
1131 // This will stop the auto-repeat of the key, should a modifier change, for example
1132 if (rec && rec->state != state) {
1133 key_recorder.findKey(int(msg.wParam), true);
1134 rec = nullptr;
1135 }
1136
1137 // Find unicode character from Windows Message Queue
1138 MSG wm_char;
1139 UINT charType = (msgType == WM_KEYDOWN
1140 ? WM_CHAR
1141 : msgType == WM_IME_KEYDOWN ? WM_IME_CHAR : WM_SYSCHAR);
1142
1143 QChar uch;
1144 if (PeekMessage(&wm_char, nullptr, charType, charType, PM_REMOVE)) {
1145 if (QWindowsContext::filterNativeEvent(&wm_char, lResult))
1146 return true;
1147 if (receiver && QWindowsContext::filterNativeEvent(receiver, &wm_char, lResult))
1148 return true;
1149 // Found a ?_CHAR
1150 uch = QChar(ushort(wm_char.wParam));
1151 if (uch.isHighSurrogate()) {
1152 m_lastHighSurrogate = uch;
1153 return true;
1154 }
1155 if (uch.isLowSurrogate() && !m_lastHighSurrogate.isNull()) {
1156 if (QObject *focusObject = QGuiApplication::focusObject()) {
1157 const QChar chars[2] = {m_lastHighSurrogate, uch};
1159 event.setCommitString(QString(chars, 2));
1160 QCoreApplication::sendEvent(focusObject, &event);
1161 }
1162 m_lastHighSurrogate = QChar();
1163 return true;
1164 } else {
1165 m_lastHighSurrogate = QChar();
1166 }
1167 if (msgType == WM_SYSKEYDOWN && uch.isLetter() && (msg.lParam & KF_ALTDOWN))
1168 uch = uch.toLower(); // (See doc of WM_SYSCHAR) Alt-letter
1169 if (!code && !uch.row())
1170 code = asciiToKeycode(char(uch.cell()), state);
1171 }
1172
1173 // Special handling for the WM_IME_KEYDOWN message. Microsoft IME (Korean) will not
1174 // generate a WM_IME_CHAR message corresponding to this message. We might get wrong
1175 // results, if we map this virtual key-code directly (for eg '?' US layouts). So try
1176 // to find the correct key using the current message parameters & keyboard state.
1177 if (uch.isNull() && msgType == WM_IME_KEYDOWN) {
1178 const auto *windowsInputContext =
1179 qobject_cast<const QWindowsInputContext *>(QWindowsIntegration::instance()->inputContext());
1181 vk_key = ImmGetVirtualKey(reinterpret_cast<HWND>(window->winId()));
1182 BYTE keyState[256];
1183 wchar_t newKey[3] = {0};
1184 GetKeyboardState(keyState);
1185 int val = ToUnicode(vk_key, scancode, keyState, newKey, 2, 0);
1186 if (val == 1) {
1187 uch = QChar(newKey[0]);
1188 } else {
1189 // If we are still not able to find a unicode key, pass the WM_IME_KEYDOWN
1190 // message to DefWindowProc() for generating a proper WM_KEYDOWN.
1191 return false;
1192 }
1193 }
1194
1195 // If no ?_CHAR was found in the queue; deduct character from the ?_KEYDOWN parameters
1196 if (uch.isNull()) {
1197 if (msg.wParam == VK_DELETE) {
1198 uch = QChar(QLatin1Char(0x7f)); // Windows doesn't know this one.
1199 } else {
1200 if (msgType != WM_SYSKEYDOWN || !code) {
1201 UINT map = MapVirtualKey(UINT(msg.wParam), 2);
1202 // If the high bit of the return value is set, it's a deadkey
1203 if (!(map & 0x80000000))
1204 uch = QChar(ushort(map));
1205 }
1206 }
1207 if (!code && !uch.row())
1208 code = asciiToKeycode(char(uch.cell()), state);
1209 }
1210
1211 // Special handling of global Windows hotkeys
1212 if (state == Qt::AltModifier) {
1213 switch (code) {
1214 case Qt::Key_Escape:
1215 case Qt::Key_Tab:
1216 case Qt::Key_F4:
1217 return false; // Send the event on to Windows
1218 case Qt::Key_Space:
1219 // do not pass this key to windows, we will process it ourselves
1220 showSystemMenu(receiver);
1221 return true;
1222 default:
1223 break;
1224 }
1225 }
1226
1227 // Map SHIFT + Tab to SHIFT + BackTab, QShortcutMap knows about this translation
1230
1231 // If we have a record, it means that the key is already pressed, the state is the same
1232 // so, we have an auto-repeating key
1233 if (rec) {
1234 if (code < Qt::Key_Shift || code > Qt::Key_ScrollLock) {
1236 Qt::KeyboardModifier(state), scancode, quint32(msg.wParam), nModifiers, rec->text, true);
1238 Qt::KeyboardModifier(state), scancode, quint32(msg.wParam), nModifiers, rec->text, true);
1239 result = true;
1240 }
1241 }
1242 // No record of the key being previous pressed, so we now send a QEvent::KeyPress event,
1243 // and store the key data into our records.
1244 else {
1245 const QString text = uch.isNull() ? QString() : QString(uch);
1246 const char a = uch.row() ? char(0) : char(uch.cell());
1247 const Qt::KeyboardModifiers modifiers(state);
1248#ifndef QT_NO_SHORTCUT
1249 // Is Qt interested in the context menu key?
1250 if (modifiers == Qt::SHIFT && code == Qt::Key_F10
1251 && !QGuiApplicationPrivate::instance()->shortcutMap.hasShortcutForKeySequence(QKeySequence(Qt::SHIFT | Qt::Key_F10))) {
1252 return false;
1253 }
1254#endif // !QT_NO_SHORTCUT
1255 key_recorder.storeKey(int(msg.wParam), a, state, text);
1256
1257 // QTBUG-71210
1258 // VK_PACKET specifies multiple characters. The system only sends the first
1259 // character of this sequence for each.
1260 if (msg.wParam == VK_PACKET)
1261 code = asciiToKeycode(char(uch.cell()), state);
1262
1264 modifiers, scancode, quint32(msg.wParam), nModifiers, text, false);
1265 result =true;
1266 bool store = true;
1267 // Alt+<alphanumerical> go to the Win32 menu system if unhandled by Qt
1268 if (msgType == WM_SYSKEYDOWN && !result && a) {
1269 HWND parent = GetParent(QWindowsWindow::handleOf(receiver));
1270 while (parent) {
1271 if (GetMenu(parent)) {
1272 SendMessage(parent, WM_SYSCOMMAND, SC_KEYMENU, a);
1273 store = false;
1274 result = true;
1275 break;
1276 }
1277 parent = GetParent(parent);
1278 }
1279 }
1280 if (!store)
1281 key_recorder.findKey(int(msg.wParam), true);
1282 }
1283 }
1284
1285 // KEYUP -----------------------------------------------------------------------------------
1286 else {
1287 // Try to locate the key in our records, and remove it if it exists.
1288 // The key may not be in our records if, for example, the down event was handled by
1289 // win32 natively, or our window gets focus while a key is already press, but now gets
1290 // the key release event.
1291 const KeyRecord *rec = key_recorder.findKey(int(msg.wParam), true);
1292 if (!rec && !(code == Qt::Key_Shift
1293 || code == Qt::Key_Control
1294 || code == Qt::Key_Meta
1295 || code == Qt::Key_Alt)) {
1296
1297 // Workaround for QTBUG-77153:
1298 // The Surface Pen eraser button generates Meta+F18/19/20 keystrokes,
1299 // but when it is not touching the screen the Fn Down is eaten and only
1300 // a Fn Up with the previous state as "not pressed" is generated, which
1301 // would be ignored. We detect this case and synthesize the expected events.
1302 if ((msg.lParam & 0x40000000) == 0 &&
1304 ((code == Qt::Key_F18) || (code == Qt::Key_F19) || (code == Qt::Key_F20))) {
1306 Qt::MetaModifier, scancode,
1307 quint32(msg.wParam), MetaLeft);
1309 Qt::NoModifier, scancode,
1310 quint32(msg.wParam), 0);
1311 result = true;
1312 }
1313 } else {
1314 if (!code)
1315 code = asciiToKeycode(rec->ascii ? char(rec->ascii) : char(msg.wParam), state);
1316
1317 // Map SHIFT + Tab to SHIFT + BackTab, QShortcutMap knows about this translation
1321 Qt::KeyboardModifier(state), scancode, quint32(msg.wParam),
1322 nModifiers,
1323 (rec ? rec->text : QString()), false);
1324 result = true;
1325 // don't pass Alt to Windows unless we are embedded in a non-Qt window
1326 if (code == Qt::Key_Alt) {
1328 HWND parent = GetParent(QWindowsWindow::handleOf(receiver));
1329 while (parent) {
1330 if (!context->findPlatformWindow(parent) && GetMenu(parent)) {
1331 result = false;
1332 break;
1333 }
1334 parent = GetParent(parent);
1335 }
1336 }
1337 }
1338 }
1339 return result;
1340}
1341
1343{
1344 Qt::KeyboardModifiers modifiers = Qt::NoModifier;
1345 if (GetKeyState(VK_SHIFT) < 0)
1347 if (GetKeyState(VK_CONTROL) < 0)
1349 if (GetKeyState(VK_MENU) < 0)
1351 if (GetKeyState(VK_LWIN) < 0 || GetKeyState(VK_RWIN) < 0)
1353 return modifiers;
1354}
1355
1357{
1359
1360
1361 const quint32 nativeVirtualKey = e->nativeVirtualKey();
1362 if (nativeVirtualKey > 255)
1363 return result;
1364
1365 const KeyboardLayoutItem &kbItem = keyLayout[nativeVirtualKey];
1366 if (!kbItem.exists)
1367 return result;
1368
1369 quint32 baseKey = kbItem.qtKey[0];
1370 Qt::KeyboardModifiers keyMods = e->modifiers();
1371 if (baseKey == Qt::Key_Return && (e->nativeModifiers() & ExtendedKey)) {
1372 result << (Qt::Key_Enter | keyMods).toCombined();
1373 return result;
1374 }
1375 result << int(baseKey) + int(keyMods); // The base key is _always_ valid, of course
1376
1377 for (size_t i = 1; i < NumMods; ++i) {
1378 Qt::KeyboardModifiers neededMods = ModsTbl[i];
1379 quint32 key = kbItem.qtKey[i];
1380 if (key && key != baseKey && ((keyMods & neededMods) == neededMods)) {
1381 const Qt::KeyboardModifiers missingMods = keyMods & ~neededMods;
1382 const int matchedKey = int(key) + int(missingMods);
1383 const auto it =
1384 std::find_if(result.begin(), result.end(),
1385 [key] (int k) { return (k & ~Qt::KeyboardModifierMask) == key; });
1386 // QTBUG-67200: Use the match with the least modifiers (prefer
1387 // Shift+9 over Alt + Shift + 9) resulting in more missing modifiers.
1388 if (it == result.end())
1389 result << matchedKey;
1390 else if (missingMods > Qt::KeyboardModifiers(*it & Qt::KeyboardModifierMask))
1391 *it = matchedKey;
1392 }
1393 }
1394 qCDebug(lcQpaEvents) << __FUNCTION__ << e << "nativeVirtualKey="
1395 << Qt::showbase << Qt::hex << e->nativeVirtualKey() << Qt::dec << Qt::noshowbase
1396 << e->modifiers() << kbItem << "\n returns" << formatKeys(result);
1397 return result;
1398}
1399
\inmodule QtCore
Definition qchar.h:48
QChar toLower() const noexcept
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition qchar.h:448
constexpr uchar row() const noexcept
Returns the row (most significant byte) of the Unicode character.
Definition qchar.h:484
constexpr bool isLowSurrogate() const noexcept
Returns true if the QChar is the low part of a UTF16 surrogate (for example if its code point is in r...
Definition qchar.h:480
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
Definition qchar.h:458
constexpr uchar cell() const noexcept
Returns the cell (least significant byte) of the Unicode character.
Definition qchar.h:483
constexpr bool isNull() const noexcept
Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false.
Definition qchar.h:463
QChar toUpper() const noexcept
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition qchar.h:449
constexpr bool isLetter() const noexcept
Returns true if the character is a letter (Letter_* categories); otherwise returns false.
Definition qchar.h:470
constexpr bool isHighSurrogate() const noexcept
Returns true if the QChar is the high part of a UTF16 surrogate (for example if its code point is in ...
Definition qchar.h:479
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
\inmodule QtCore
\inmodule QtCore
@ KeyRelease
Definition qcoreevent.h:65
@ KeyPress
Definition qcoreevent.h:64
static QGuiApplicationPrivate * instance()
\macro qGuiApp
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
void applicationStateChanged(Qt::ApplicationState state)
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
The QKeyEvent class describes a key event.
Definition qevent.h:423
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
iterator end()
Definition qset.h:140
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text=QString(), bool autorep=false, ushort count=1)
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
static HWND handleOf(const QWindow *w)
Singleton container for all relevant information.
static QWindowsContext * instance()
static bool filterNativeEvent(MSG *msg, LRESULT *result)
static QWindowsIntegration * instance()
bool translateKeyEvent(QWindow *widget, HWND hwnd, const MSG &msg, LRESULT *result)
To be called from the window procedure.
static Qt::KeyboardModifiers queryKeyboardModifiers()
QList< int > possibleKeys(const QKeyEvent *e) const
static QWindow * topLevelOf(QWindow *w)
friend QDebug operator<<(QDebug d, const formatKeys &keys)
formatKeys(const QList< int > &keys)
EGLImageKHR int int EGLuint64KHR * modifiers
QOpenGLWidget * widget
[1]
QMap< QString, QString > map
[6]
QString text
double e
QSet< QString >::iterator it
else opt state
[0]
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
static void formatQEnum(QDebug &debug, QEnum value)
Definition qdebug_p.h:59
static void formatQFlags(QDebug &debug, const QFlags< Enum > &value)
Definition qdebug_p.h:79
constexpr char toAsciiUpper(char ch) noexcept
Definition qtools_p.h:92
@ SHIFT
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
QTextStream & showbase(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and r...
@ LeftToRight
@ RightToLeft
QTextStream & noshowbase(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and ...
@ Key_Escape
Definition qnamespace.h:658
@ Key_BassBoost
Definition qnamespace.h:848
@ Key_AltGr
Definition qnamespace.h:734
@ Key_Favorites
Definition qnamespace.h:861
@ Key_Copy
Definition qnamespace.h:912
@ Key_F20
Definition qnamespace.h:704
@ Key_MediaPrevious
Definition qnamespace.h:855
@ Key_Tab
Definition qnamespace.h:659
@ Key_LaunchMail
Definition qnamespace.h:865
@ Key_Select
@ Key_MailForward
Definition qnamespace.h:956
@ Key_Plus
Definition qnamespace.h:524
@ Key_Shift
Definition qnamespace.h:678
@ Key_Return
Definition qnamespace.h:662
@ Key_9
Definition qnamespace.h:538
@ Key_Right
Definition qnamespace.h:674
@ Key_Enter
Definition qnamespace.h:663
@ Key_F7
Definition qnamespace.h:691
@ Key_PageUp
Definition qnamespace.h:676
@ Key_Printer
@ Key_F22
Definition qnamespace.h:706
@ Key_Execute
@ Key_F23
Definition qnamespace.h:707
@ Key_Cancel
@ Key_Space
Definition qnamespace.h:512
@ Key_ChannelDown
Definition qnamespace.h:992
@ Key_MediaTogglePlayPause
Definition qnamespace.h:859
@ Key_4
Definition qnamespace.h:533
@ Key_2
Definition qnamespace.h:531
@ Key_F24
Definition qnamespace.h:708
@ Key_F17
Definition qnamespace.h:701
@ Key_F21
Definition qnamespace.h:705
@ Key_Open
@ Key_7
Definition qnamespace.h:536
@ Key_Undo
@ Key_8
Definition qnamespace.h:537
@ Key_Backspace
Definition qnamespace.h:661
@ Key_VolumeUp
Definition qnamespace.h:847
@ Key_Backtab
Definition qnamespace.h:660
@ Key_Direction_L
Definition qnamespace.h:726
@ Key_F6
Definition qnamespace.h:690
@ Key_VolumeDown
Definition qnamespace.h:845
@ Key_HomePage
Definition qnamespace.h:860
@ Key_Insert
Definition qnamespace.h:664
@ Key_New
@ Key_Touroku
Definition qnamespace.h:757
@ Key_Left
Definition qnamespace.h:672
@ Key_Cut
Definition qnamespace.h:913
@ Key_MicVolumeDown
Definition qnamespace.h:999
@ Key_0
Definition qnamespace.h:529
@ Key_Control
Definition qnamespace.h:679
@ Key_F9
Definition qnamespace.h:693
@ Key_Redo
@ Key_AudioRewind
Definition qnamespace.h:902
@ Key_Alt
Definition qnamespace.h:681
@ Key_VolumeMute
Definition qnamespace.h:846
@ Key_Find
@ Key_F11
Definition qnamespace.h:695
@ Key_ChannelUp
Definition qnamespace.h:991
@ Key_Print
Definition qnamespace.h:667
@ Key_Pause
Definition qnamespace.h:666
@ Key_1
Definition qnamespace.h:530
@ Key_MicVolumeUp
Definition qnamespace.h:998
@ Key_Up
Definition qnamespace.h:673
@ Key_Minus
Definition qnamespace.h:526
@ Key_TrebleUp
Definition qnamespace.h:851
@ Key_TrebleDown
Definition qnamespace.h:852
@ Key_F3
Definition qnamespace.h:687
@ Key_F16
Definition qnamespace.h:700
@ Key_Down
Definition qnamespace.h:675
@ Key_F18
Definition qnamespace.h:702
@ Key_LaunchMedia
Definition qnamespace.h:866
@ Key_6
Definition qnamespace.h:535
@ Key_Close
Definition qnamespace.h:911
@ Key_F4
Definition qnamespace.h:688
@ Key_MediaPause
Definition qnamespace.h:858
@ Key_Refresh
Definition qnamespace.h:844
@ Key_Spell
Definition qnamespace.h:941
@ Key_Save
Definition qnamespace.h:939
@ Key_BassUp
Definition qnamespace.h:849
@ Key_F2
Definition qnamespace.h:686
@ Key_Delete
Definition qnamespace.h:665
@ Key_NumLock
Definition qnamespace.h:683
@ Key_Meta
Definition qnamespace.h:680
@ Key_Forward
Definition qnamespace.h:842
@ Key_Launch0
Definition qnamespace.h:867
@ Key_Help
Definition qnamespace.h:725
@ Key_ScrollLock
Definition qnamespace.h:684
@ Key_Send
Definition qnamespace.h:940
@ Key_Sleep
@ Key_MediaRecord
Definition qnamespace.h:857
@ Key_F1
Definition qnamespace.h:685
@ Key_Direction_R
Definition qnamespace.h:727
@ Key_Play
@ Key_3
Definition qnamespace.h:532
@ Key_F14
Definition qnamespace.h:698
@ Key_Slash
Definition qnamespace.h:528
@ Key_Period
Definition qnamespace.h:527
@ Key_Menu
Definition qnamespace.h:722
@ Key_BassDown
Definition qnamespace.h:850
@ Key_PageDown
Definition qnamespace.h:677
@ Key_F19
Definition qnamespace.h:703
@ Key_Launch1
Definition qnamespace.h:868
@ Key_F5
Definition qnamespace.h:689
@ Key_Back
Definition qnamespace.h:841
@ Key_Home
Definition qnamespace.h:670
@ Key_F10
Definition qnamespace.h:694
@ Key_Clear
Definition qnamespace.h:669
@ Key_Massyo
Definition qnamespace.h:758
@ Key_Mode_switch
Definition qnamespace.h:742
@ Key_Comma
Definition qnamespace.h:525
@ Key_MediaStop
Definition qnamespace.h:854
@ Key_F8
Definition qnamespace.h:692
@ Key_F13
Definition qnamespace.h:697
@ Key_CapsLock
Definition qnamespace.h:682
@ Key_Zoom
@ Key_MicMute
Definition qnamespace.h:984
@ Key_MediaPlay
Definition qnamespace.h:853
@ Key_Search
Definition qnamespace.h:862
@ Key_Paste
Definition qnamespace.h:931
@ Key_Asterisk
Definition qnamespace.h:523
@ Key_Stop
Definition qnamespace.h:843
@ Key_5
Definition qnamespace.h:534
@ Key_F12
Definition qnamespace.h:696
@ Key_unknown
@ Key_Reply
Definition qnamespace.h:934
@ Key_F15
Definition qnamespace.h:699
@ Key_AudioForward
Definition qnamespace.h:963
@ Key_MediaNext
Definition qnamespace.h:856
@ Key_End
Definition qnamespace.h:671
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
KeyboardModifier
@ ShiftModifier
@ ControlModifier
@ MetaModifier
@ GroupSwitchModifier
@ KeypadModifier
@ KeyboardModifierMask
@ NoModifier
@ AltModifier
ApplicationState
Definition qnamespace.h:261
@ ApplicationInactive
Definition qnamespace.h:264
@ CustomizeWindowHint
Definition qnamespace.h:238
@ FramelessWindowHint
Definition qnamespace.h:224
@ WindowContextHelpButtonHint
Definition qnamespace.h:230
@ MSWindowsFixedSizeDialogHint
Definition qnamespace.h:220
@ WindowMaximizeButtonHint
Definition qnamespace.h:228
@ WindowMinimizeButtonHint
Definition qnamespace.h:227
@ WindowMinMaxButtonsHint
Definition qnamespace.h:229
@ WindowTitleHint
Definition qnamespace.h:225
@ WindowSystemMenuHint
Definition qnamespace.h:226
@ WindowCloseButtonHint
Definition qnamespace.h:240
static void * context
static QT_WARNING_DISABLE_FLOAT_COMPARE ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
Definition qbezier.cpp:309
#define Q_FALLTHROUGH()
#define qWarning
Definition qlogging.h:162
#define qCDebug(category,...)
return ret
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint buffer
GLbitfield flags
struct _cl_event * event
GLuint res
const GLubyte * c
GLuint GLfloat * val
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
static QString qtKey(CFStringRef cfkey)
unsigned int quint32
Definition qtypes.h:45
size_t quintptr
Definition qtypes.h:72
unsigned int uint
Definition qtypes.h:29
unsigned short ushort
Definition qtypes.h:28
struct tagMSG MSG
static QWindowsInputContext * windowsInputContext()
LRESULT QT_WIN_CALLBACK qWindowsWndProc(HWND, UINT, WPARAM, LPARAM)
static const size_t NumMods
#define enabled
static const uint CmdTbl[]
static bool isAltGr(MSG *msg)
static KeyRecorder key_recorder
static void sendExtendedPressRelease(QWindow *w, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text=QString(), bool autorep=false, ushort count=1)
static int asciiToKeycode(char a, int state)
static const uint KeyTbl[]
#define disabled
#define VK_OEM_PLUS
@ scancodeBitmask
static int getTitleBarHeight(const HWND hwnd)
QDebug operator<<(QDebug d, const KeyboardLayoutItem &k)
quint32 winceKeyBend(quint32 keyCode)
static QString messageKeyText(const MSG &msg)
static const int QT_MAX_KEY_RECORDINGS
void setKbdState(unsigned char *kbd, bool shift, bool ctrl, bool alt)
static quint32 toKeyOrUnicode(quint32 vk, quint32 scancode, unsigned char *kbdBuffer, bool *isDeadkey=nullptr)
static void clearKeyRecorderOnApplicationInActive(Qt::ApplicationState state)
static bool isSystemMenuOffsetNeeded(const Qt::WindowFlags flags)
static void showSystemMenu(QWindow *w)
static const Qt::KeyboardModifiers ModsTbl[]
#define VK_OEM_3
@ ScrollLock
@ ExtendedKey
@ ShiftRight
@ AltLeft
@ ShiftLeft
@ MetaRight
@ AltAny
@ MetaLeft
@ MetaAny
@ AltRight
@ ControlLeft
@ ControlRight
@ CapsLock
@ NumLock
@ ShiftAny
@ ControlAny
static const Qt::KeyboardModifiers ModsTbl[]
QStringList keys
settings remove("monkey")
QObject::connect nullptr
QApplication app(argc, argv)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QMenu menu
[5]
KeyRecord(int c, int a, int s, const QString &t)
KeyRecord records[QT_MAX_KEY_RECORDINGS]
void storeKey(int code, int ascii, int state, const QString &text)
KeyRecord deleted_record
KeyRecord * findKey(int code, bool remove)
quint32 qtKey[NumQtKeys]
static const size_t NumQtKeys
\inmodule QtCore \reentrant
Definition qchar.h:17
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent