1 /* Test Key event to Key message translation
2 *
3 * Copyright 2003 Rein Klazes
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 /* test whether the right type of messages:
21 * WM_KEYUP/DOWN vs WM_SYSKEYUP/DOWN are sent in case of combined
22 * keystrokes.
23 *
24 * For instance <ALT>-X can be accomplished by
25 * the sequence ALT-KEY-DOWN, X-KEY-DOWN, ALT-KEY-UP, X-KEY-UP
26 * but also X-KEY-DOWN, ALT-KEY-DOWN, X-KEY-UP, ALT-KEY-UP
27 * Whether a KEY or a SYSKEY message is sent is not always clear, it is
28 * also not the same in WINNT as in WIN9X */
29
30 /* NOTE that there will be test failures under WIN9X
31 * No applications are known to me that rely on this
32 * so I don't fix it */
33
34 /* TODO:
35 * 1. extend it to the wm_command and wm_syscommand notifications
36 * 2. add some more tests with special cases like dead keys or right (alt) key
37 * 3. there is some adapted code from input.c in here. Should really
38 * make that code exactly the same.
39 * 4. resolve the win9x case when there is a need or the testing frame work
40 * offers a nice way.
41 * 5. The test app creates a window, the user should not take the focus
42 * away during its short existence. I could do something to prevent that
43 * if it is a problem.
44 *
45 */
46
47 #define _WIN32_WINNT 0x401
48 #define _WIN32_IE 0x0500
49
50 #include <stdarg.h>
51 #include <assert.h>
52
53 #include "windef.h"
54 #include "winbase.h"
55 #include "winuser.h"
56
57 #include "wine/test.h"
58
59 /* globals */
60 static HWND hWndTest;
61 static long timetag = 0x10000000;
62
63 static UINT (WINAPI *pSendInput) (UINT, INPUT*, size_t);
64 static int (WINAPI *pGetMouseMovePointsEx) (UINT, LPMOUSEMOVEPOINT, LPMOUSEMOVEPOINT, int, DWORD);
65
66 #define MAXKEYEVENTS 6
67 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
68 and only one message */
69
70 /* keyboard message names, sorted as their value */
71 static const char *MSGNAME[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
72 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
73
74 /* keyevents, add more as needed */
75 typedef enum KEVtag
76 { ALTDOWN = 1, ALTUP, XDOWN, XUP, SHIFTDOWN, SHIFTUP, CTRLDOWN, CTRLUP } KEV;
77 /* matching VK's */
78 static const int GETVKEY[]={0, VK_MENU, VK_MENU, 'X', 'X', VK_SHIFT, VK_SHIFT, VK_CONTROL, VK_CONTROL};
79 /* matching scan codes */
80 static const int GETSCAN[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
81 /* matching updown events */
82 static const int GETFLAGS[]={0, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP};
83 /* matching descriptions */
84 static const char *getdesc[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
85
86 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
87 typedef struct
88 {
89 DWORD type;
90 union
91 {
92 MOUSEINPUT mi;
93 KEYBDINPUT ki;
94 HARDWAREINPUT hi;
95 } u;
96 } TEST_INPUT;
97
98 #define ADDTOINPUTS(kev) \
99 inputs[evtctr].type = INPUT_KEYBOARD; \
100 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
101 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
102 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETFLAGS[ kev]; \
103 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
104 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
105 if( kev) evtctr++;
106
107 typedef struct {
108 UINT message;
109 WPARAM wParam;
110 LPARAM lParam;
111 } KMSG;
112
113 /*******************************************
114 * add new test sets here
115 * the software will make all combinations of the
116 * keyevent defined here
117 */
118 static const struct {
119 int nrkev;
120 KEV keydwn[MAXKEYEVENTS];
121 KEV keyup[MAXKEYEVENTS];
122 } testkeyset[]= {
123 { 2, { ALTDOWN, XDOWN }, { ALTUP, XUP}},
124 { 3, { ALTDOWN, XDOWN , SHIFTDOWN}, { ALTUP, XUP, SHIFTUP}},
125 { 3, { ALTDOWN, XDOWN , CTRLDOWN}, { ALTUP, XUP, CTRLUP}},
126 { 3, { SHIFTDOWN, XDOWN , CTRLDOWN}, { SHIFTUP, XUP, CTRLUP}},
127 { 0 } /* mark the end */
128 };
129
130 /**********************adapted from input.c **********************************/
131
132 static BYTE InputKeyStateTable[256];
133 static BYTE AsyncKeyStateTable[256];
134 static BYTE TrackSysKey = 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
135 or a WM_KEYUP message */
136
137 static void init_function_pointers(void)
138 {
139 HMODULE hdll = GetModuleHandleA("user32");
140
141 #define GET_PROC(func) \
142 p ## func = (void*)GetProcAddress(hdll, #func); \
143 if(!p ## func) \
144 trace("GetProcAddress(%s) failed\n", #func);
145
146 GET_PROC(SendInput)
147 GET_PROC(GetMouseMovePointsEx)
148
149 #undef GET_PROC
150 }
151
152 static int KbdMessage( KEV kev, WPARAM *pwParam, LPARAM *plParam )
153 {
154 UINT message;
155 int VKey = GETVKEY[kev];
156 WORD flags;
157
158 flags = LOBYTE(GETSCAN[kev]);
159 if (GETFLAGS[kev] & KEYEVENTF_EXTENDEDKEY) flags |= KF_EXTENDED;
160
161 if (GETFLAGS[kev] & KEYEVENTF_KEYUP )
162 {
163 message = WM_KEYUP;
164 if( (InputKeyStateTable[VK_MENU] & 0x80) && (
165 (VKey == VK_MENU) || (VKey == VK_CONTROL) ||
166 !(InputKeyStateTable[VK_CONTROL] & 0x80))) {
167 if( TrackSysKey == VK_MENU || /* <ALT>-down/<ALT>-up sequence */
168 (VKey != VK_MENU)) /* <ALT>-down...<something else>-up */
169 message = WM_SYSKEYUP;
170 TrackSysKey = 0;
171 }
172 InputKeyStateTable[VKey] &= ~0x80;
173 flags |= KF_REPEAT | KF_UP;
174 }
175 else
176 {
177 if (InputKeyStateTable[VKey] & 0x80) flags |= KF_REPEAT;
178 if (!(InputKeyStateTable[VKey] & 0x80)) InputKeyStateTable[VKey] ^= 0x01;
179 InputKeyStateTable[VKey] |= 0x80;
180 AsyncKeyStateTable[VKey] |= 0x80;
181
182 message = WM_KEYDOWN;
183 if( (InputKeyStateTable[VK_MENU] & 0x80) &&
184 !(InputKeyStateTable[VK_CONTROL] & 0x80)) {
185 message = WM_SYSKEYDOWN;
186 TrackSysKey = VKey;
187 }
188 }
189
190 if (InputKeyStateTable[VK_MENU] & 0x80) flags |= KF_ALTDOWN;
191
192 if( plParam) *plParam = MAKELPARAM( 1, flags );
193 if( pwParam) *pwParam = VKey;
194 return message;
195 }
196
197 /****************************** end copy input.c ****************************/
198
199 /*
200 * . prepare the keyevents for SendInputs
201 * . calculate the "expected" messages
202 * . Send the events to our window
203 * . retrieve the messages from the input queue
204 * . verify
205 */
206 static void do_test( HWND hwnd, int seqnr, const KEV td[] )
207 {
208 INPUT inputs[MAXKEYEVENTS];
209 KMSG expmsg[MAXKEYEVENTS];
210 MSG msg;
211 char buf[100];
212 UINT evtctr=0;
213 int kmctr, i;
214
215 buf[0]='\0';
216 TrackSysKey=0; /* see input.c */
217 for( i = 0; i < MAXKEYEVENTS; i++) {
218 ADDTOINPUTS(td[i])
219 strcat(buf, getdesc[td[i]]);
220 if(td[i])
221 expmsg[i].message = KbdMessage(td[i], &(expmsg[i].wParam), &(expmsg[i].lParam)); /* see queue_kbd_event() */
222 else
223 expmsg[i].message = 0;
224 }
225 for( kmctr = 0; kmctr < MAXKEYEVENTS && expmsg[kmctr].message; kmctr++)
226 ;
227 assert( evtctr <= MAXKEYEVENTS );
228 assert( evtctr == pSendInput(evtctr, &inputs[0], sizeof(INPUT)));
229 i = 0;
230 if (winetest_debug > 1)
231 trace("======== key stroke sequence #%d: %s =============\n",
232 seqnr + 1, buf);
233 while( PeekMessage(&msg,hwnd,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE) ) {
234 if (winetest_debug > 1)
235 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i,
236 MSGNAME[msg.message - WM_KEYFIRST], msg.wParam, msg.lParam, msg.time);
237 if( i < kmctr ) {
238 ok( msg.message == expmsg[i].message &&
239 msg.wParam == expmsg[i].wParam &&
240 msg.lParam == expmsg[i].lParam,
241 "wrong message! expected:\n"
242 "message[%d] %-15s wParam %04lx lParam %08lx\n",i,
243 MSGNAME[(expmsg[i]).message - WM_KEYFIRST],
244 expmsg[i].wParam, expmsg[i].lParam );
245 }
246 i++;
247 }
248 if (winetest_debug > 1)
249 trace("%d messages retrieved\n", i);
250 ok( i == kmctr, "message count is wrong: got %d expected: %d\n", i, kmctr);
251 }
252
253 /* test all combinations of the specified key events */
254 static void TestASet( HWND hWnd, int nrkev, const KEV kevdwn[], const KEV kevup[] )
255 {
256 int i,j,k,l,m,n;
257 static int count=0;
258 KEV kbuf[MAXKEYEVENTS];
259 assert( nrkev==2 || nrkev==3);
260 for(i=0;i<MAXKEYEVENTS;i++) kbuf[i]=0;
261 /* two keys involved gives 4 test cases */
262 if(nrkev==2) {
263 for(i=0;i<nrkev;i++) {
264 for(j=0;j<nrkev;j++) {
265 kbuf[0] = kevdwn[i];
266 kbuf[1] = kevdwn[1-i];
267 kbuf[2] = kevup[j];
268 kbuf[3] = kevup[1-j];
269 do_test( hWnd, count++, kbuf);
270 }
271 }
272 }
273 /* three keys involved gives 36 test cases */
274 if(nrkev==3){
275 for(i=0;i<nrkev;i++){
276 for(j=0;j<nrkev;j++){
277 if(j==i) continue;
278 for(k=0;k<nrkev;k++){
279 if(k==i || k==j) continue;
280 for(l=0;l<nrkev;l++){
281 for(m=0;m<nrkev;m++){
282 if(m==l) continue;
283 for(n=0;n<nrkev;n++){
284 if(n==l ||n==m) continue;
285 kbuf[0] = kevdwn[i];
286 kbuf[1] = kevdwn[j];
287 kbuf[2] = kevdwn[k];
288 kbuf[3] = kevup[l];
289 kbuf[4] = kevup[m];
290 kbuf[5] = kevup[n];
291 do_test( hWnd, count++, kbuf);
292 }
293 }
294 }
295 }
296 }
297 }
298 }
299 }
300
301 /* test each set specified in the global testkeyset array */
302 static void TestSysKeys( HWND hWnd)
303 {
304 int i;
305 for(i=0; testkeyset[i].nrkev;i++)
306 TestASet( hWnd, testkeyset[i].nrkev, testkeyset[i].keydwn,
307 testkeyset[i].keyup);
308 }
309
310 static LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam,
311 LPARAM lParam )
312 {
313 switch (msg) {
314 case WM_USER:
315 SetFocus(hWnd);
316 /* window has focus, now do the test */
317 if( hWnd == hWndTest) TestSysKeys( hWnd);
318 /* finished :-) */
319 break;
320
321 case WM_DESTROY:
322 PostQuitMessage( 0 );
323 break;
324
325 default:
326 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
327 }
328
329 return 0;
330 }
331
332 static void test_Input_whitebox(void)
333 {
334 MSG msg;
335 WNDCLASSA wclass;
336 HANDLE hInstance = GetModuleHandleA( NULL );
337
338 wclass.lpszClassName = "InputSysKeyTestClass";
339 wclass.style = CS_HREDRAW | CS_VREDRAW;
340 wclass.lpfnWndProc = WndProc;
341 wclass.hInstance = hInstance;
342 wclass.hIcon = LoadIconA( 0, (LPSTR)IDI_APPLICATION );
343 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW);
344 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1);
345 wclass.lpszMenuName = 0;
346 wclass.cbClsExtra = 0;
347 wclass.cbWndExtra = 0;
348 assert (RegisterClassA( &wclass ));
349 /* create the test window that will receive the keystrokes */
350 assert ( hWndTest = CreateWindowA( wclass.lpszClassName, "InputSysKeyTest",
351 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
352 NULL, NULL, hInstance, NULL) );
353 ShowWindow( hWndTest, SW_SHOW);
354 UpdateWindow( hWndTest);
355
356 /* flush pending messages */
357 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
358
359 SendMessageA(hWndTest, WM_USER, 0, 0);
360 DestroyWindow(hWndTest);
361 }
362
363 /* try to make sure pending X events have been processed before continuing */
364 static void empty_message_queue(void)
365 {
366 MSG msg;
367 int diff = 200;
368 int min_timeout = 50;
369 DWORD time = GetTickCount() + diff;
370
371 while (diff > 0)
372 {
373 if (MsgWaitForMultipleObjects(0, NULL, FALSE, min_timeout, QS_ALLINPUT) == WAIT_TIMEOUT) break;
374 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
375 {
376 TranslateMessage(&msg);
377 DispatchMessage(&msg);
378 }
379 diff = time - GetTickCount();
380 min_timeout = 20;
381 }
382 }
383
384 struct transition_s {
385 WORD wVk;
386 BYTE before_state;
387 BYTE optional;
388 };
389
390 typedef enum {
391 sent=0x1,
392 posted=0x2,
393 parent=0x4,
394 wparam=0x8,
395 lparam=0x10,
396 defwinproc=0x20,
397 beginpaint=0x40,
398 optional=0x80,
399 hook=0x100,
400 winevent_hook=0x200
401 } msg_flags_t;
402
403 struct message {
404 UINT message; /* the WM_* code */
405 msg_flags_t flags; /* message props */
406 WPARAM wParam; /* expected value of wParam */
407 LPARAM lParam; /* expected value of lParam */
408 };
409
410 struct sendinput_test_s {
411 WORD wVk;
412 DWORD dwFlags;
413 BOOL _todo_wine;
414 struct transition_s expected_transitions[MAXKEYEVENTS+1];
415 struct message expected_messages[MAXKEYMESSAGES+1];
416 } sendinput_test[] = {
417 /* test ALT+F */
418 /* 0 */
419 {VK_LMENU, 0, 0, {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
420 {{WM_SYSKEYDOWN, hook|wparam, VK_LMENU}, {WM_SYSKEYDOWN}, {0}}},
421 {'F', 0, 0, {{'F', 0x00}, {0}},
422 {{WM_SYSKEYDOWN, hook}, {WM_SYSKEYDOWN},
423 {WM_SYSCHAR},
424 {WM_SYSCOMMAND}, {0}}},
425 {'F', KEYEVENTF_KEYUP, 0, {{'F', 0x80}, {0}},
426 {{WM_SYSKEYUP, hook}, {WM_SYSKEYUP}, {0}}},
427 {VK_LMENU, KEYEVENTF_KEYUP, 0, {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
428 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
429
430 /* test CTRL+O */
431 /* 4 */
432 {VK_LCONTROL, 0, 0, {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
433 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
434 {'O', 0, 0, {{'O', 0x00}, {0}},
435 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {WM_CHAR}, {0}}},
436 {'O', KEYEVENTF_KEYUP, 0, {{'O', 0x80}, {0}},
437 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
438 {VK_LCONTROL, KEYEVENTF_KEYUP, 0, {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
439 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
440
441 /* test ALT+CTRL+X */
442 /* 8 */
443 {VK_LMENU, 0, 0, {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
444 {{WM_SYSKEYDOWN, hook}, {WM_SYSKEYDOWN}, {0}}},
445 {VK_LCONTROL, 0, 0, {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
446 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
447 {'X', 0, 0, {{'X', 0x00}, {0}},
448 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
449 {'X', KEYEVENTF_KEYUP, 0, {{'X', 0x80}, {0}},
450 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
451 {VK_LCONTROL, KEYEVENTF_KEYUP, 0, {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
452 {{WM_SYSKEYUP, hook}, {WM_SYSKEYUP}, {0}}},
453 {VK_LMENU, KEYEVENTF_KEYUP, 0, {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
454 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
455
456 /* test SHIFT+A */
457 /* 14 */
458 {VK_LSHIFT, 0, 0, {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
459 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
460 {'A', 0, 0, {{'A', 0x00}, {0}},
461 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {WM_CHAR}, {0}}},
462 {'A', KEYEVENTF_KEYUP, 0, {{'A', 0x80}, {0}},
463 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
464 {VK_LSHIFT, KEYEVENTF_KEYUP, 0, {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
465 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
466 /* test L-SHIFT & R-SHIFT: */
467 /* RSHIFT == LSHIFT */
468 /* 18 */
469 {VK_RSHIFT, 0, 0,
470 /* recent windows versions (>= w2k3) correctly report an RSHIFT transition */
471 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00, TRUE}, {VK_RSHIFT, 0x00, TRUE}, {0}},
472 {{WM_KEYDOWN, hook|wparam, VK_RSHIFT},
473 {WM_KEYDOWN}, {0}}},
474 {VK_RSHIFT, KEYEVENTF_KEYUP, 0,
475 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80, TRUE}, {VK_RSHIFT, 0x80, TRUE}, {0}},
476 {{WM_KEYUP, hook, hook|wparam, VK_RSHIFT},
477 {WM_KEYUP}, {0}}},
478
479 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
480 /* 20 */
481 {VK_LSHIFT, KEYEVENTF_EXTENDEDKEY, 0,
482 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
483 {{WM_KEYDOWN, hook|wparam|lparam, VK_LSHIFT, LLKHF_EXTENDED},
484 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
485 {VK_LSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
486 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
487 {{WM_KEYUP, hook|wparam|lparam, VK_LSHIFT, LLKHF_UP|LLKHF_EXTENDED},
488 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
489 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
490 /* 22 */
491 {VK_RSHIFT, KEYEVENTF_EXTENDEDKEY, 0,
492 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
493 {{WM_KEYDOWN, hook|wparam|lparam, VK_RSHIFT, LLKHF_EXTENDED},
494 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
495 {VK_RSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
496 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
497 {{WM_KEYUP, hook|wparam|lparam, VK_RSHIFT, LLKHF_UP|LLKHF_EXTENDED},
498 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
499
500 /* Note about wparam for hook with generic key (VK_SHIFT, VK_CONTROL, VK_MENU):
501 win2k - sends to hook whatever we generated here
502 winXP+ - Attempts to convert key to L/R key but not always correct
503 */
504 /* SHIFT == LSHIFT */
505 /* 24 */
506 {VK_SHIFT, 0, 0,
507 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
508 {{WM_KEYDOWN, hook/* |wparam */|lparam, VK_SHIFT, 0},
509 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
510 {VK_SHIFT, KEYEVENTF_KEYUP, 0,
511 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
512 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_SHIFT, LLKHF_UP},
513 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
514 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
515 /* 26 */
516 {VK_SHIFT, KEYEVENTF_EXTENDEDKEY, 0,
517 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
518 {{WM_KEYDOWN, hook/*|wparam*/|lparam, VK_SHIFT, LLKHF_EXTENDED},
519 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
520 {VK_SHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
521 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
522 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_SHIFT, LLKHF_UP|LLKHF_EXTENDED},
523 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
524
525 /* test L-CONTROL & R-CONTROL: */
526 /* RCONTROL == LCONTROL */
527 /* 28 */
528 {VK_RCONTROL, 0, 0,
529 {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
530 {{WM_KEYDOWN, hook|wparam, VK_RCONTROL},
531 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, 0}, {0}}},
532 {VK_RCONTROL, KEYEVENTF_KEYUP, 0,
533 {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
534 {{WM_KEYUP, hook|wparam, VK_RCONTROL},
535 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP}, {0}}},
536 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
537 /* 30 */
538 {VK_LCONTROL, KEYEVENTF_EXTENDEDKEY, 0,
539 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
540 {{WM_KEYDOWN, hook|wparam|lparam, VK_LCONTROL, LLKHF_EXTENDED},
541 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
542 {VK_LCONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
543 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
544 {{WM_KEYUP, hook|wparam|lparam, VK_LCONTROL, LLKHF_UP|LLKHF_EXTENDED},
545 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
546 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
547 /* 32 */
548 {VK_RCONTROL, KEYEVENTF_EXTENDEDKEY, 0,
549 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
550 {{WM_KEYDOWN, hook|wparam|lparam, VK_RCONTROL, LLKHF_EXTENDED},
551 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
552 {VK_RCONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
553 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
554 {{WM_KEYUP, hook|wparam|lparam, VK_RCONTROL, LLKHF_UP|LLKHF_EXTENDED},
555 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
556 /* CONTROL == LCONTROL */
557 /* 34 */
558 {VK_CONTROL, 0, 0,
559 {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
560 {{WM_KEYDOWN, hook/*|wparam, VK_CONTROL*/},
561 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, 0}, {0}}},
562 {VK_CONTROL, KEYEVENTF_KEYUP, 0,
563 {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
564 {{WM_KEYUP, hook/*|wparam, VK_CONTROL*/},
565 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP}, {0}}},
566 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
567 /* 36 */
568 {VK_CONTROL, KEYEVENTF_EXTENDEDKEY, 0,
569 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
570 {{WM_KEYDOWN, hook/*|wparam*/|lparam, VK_CONTROL, LLKHF_EXTENDED},
571 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
572 {VK_CONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
573 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
574 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_CONTROL, LLKHF_UP|LLKHF_EXTENDED},
575 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
576
577 /* test L-MENU & R-MENU: */
578 /* RMENU == LMENU */
579 /* 38 */
580 {VK_RMENU, 0, 0,
581 {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
582 {{WM_SYSKEYDOWN, hook|wparam, VK_RMENU},
583 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0}, {0}}},
584 {VK_RMENU, KEYEVENTF_KEYUP, 1,
585 {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
586 {{WM_KEYUP, hook|wparam, VK_RMENU},
587 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP},
588 {WM_SYSCOMMAND}, {0}}},
589 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
590 /* 40 */
591 {VK_LMENU, KEYEVENTF_EXTENDEDKEY, 0,
592 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
593 {{WM_SYSKEYDOWN, hook|wparam|lparam, VK_LMENU, LLKHF_EXTENDED},
594 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
595 {VK_LMENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 1,
596 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
597 {{WM_KEYUP, hook|wparam|lparam, VK_LMENU, LLKHF_UP|LLKHF_EXTENDED},
598 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
599 {WM_SYSCOMMAND}, {0}}},
600 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
601 /* 42 */
602 {VK_RMENU, KEYEVENTF_EXTENDEDKEY, 0,
603 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
604 {{WM_SYSKEYDOWN, hook|wparam|lparam, VK_RMENU, LLKHF_EXTENDED},
605 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
606 {VK_RMENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 1,
607 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
608 {{WM_KEYUP, hook|wparam|lparam, VK_RMENU, LLKHF_UP|LLKHF_EXTENDED},
609 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
610 {WM_SYSCOMMAND}, {0}}},
611 /* MENU == LMENU */
612 /* 44 */
613 {VK_MENU, 0, 0,
614 {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
615 {{WM_SYSKEYDOWN, hook/*|wparam, VK_MENU*/},
616 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0}, {0}}},
617 {VK_MENU, KEYEVENTF_KEYUP, 1,
618 {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
619 {{WM_KEYUP, hook/*|wparam, VK_MENU*/},
620 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP},
621 {WM_SYSCOMMAND}, {0}}},
622 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
623 /* 46 */
624 {VK_MENU, KEYEVENTF_EXTENDEDKEY, 0,
625 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
626 {{WM_SYSKEYDOWN, hook/*|wparam*/|lparam, VK_MENU, LLKHF_EXTENDED},
627 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
628 {VK_MENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 1,
629 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
630 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_MENU, LLKHF_UP|LLKHF_EXTENDED},
631 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
632 {WM_SYSCOMMAND}, {0}}},
633
634 /* test LSHIFT & RSHIFT */
635 /* 48 */
636 {VK_LSHIFT, 0, 0,
637 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
638 {{WM_KEYDOWN, hook|wparam|lparam, VK_LSHIFT, 0},
639 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
640 {VK_RSHIFT, KEYEVENTF_EXTENDEDKEY, 0,
641 {{VK_RSHIFT, 0x00}, {0}},
642 {{WM_KEYDOWN, hook|wparam|lparam, VK_RSHIFT, LLKHF_EXTENDED},
643 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
644 {VK_RSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
645 {{VK_RSHIFT, 0x80}, {0}},
646 {{WM_KEYUP, hook|wparam|lparam, VK_RSHIFT, LLKHF_UP|LLKHF_EXTENDED},
647 {WM_KEYUP, optional}, {0}}},
648 {VK_LSHIFT, KEYEVENTF_KEYUP, 0,
649 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
650 {{WM_KEYUP, hook|wparam, VK_LSHIFT},
651 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
652
653 {0, 0, 0, {{0}}, {{0}}} /* end */
654 };
655
656 static struct message sent_messages[MAXKEYMESSAGES];
657 static UINT sent_messages_cnt;
658
659 /* Verify that only specified key state transitions occur */
660 static void compare_and_check(int id, BYTE *ks1, BYTE *ks2, struct sendinput_test_s *test)
661 {
662 int i, failcount = 0;
663 struct transition_s *t = test->expected_transitions;
664 UINT actual_cnt = 0;
665 const struct message *expected = test->expected_messages;
666
667 while (t->wVk) {
668 int matched = ((ks1[t->wVk]&0x80) == (t->before_state&0x80)
669 && (ks2[t->wVk]&0x80) == (~t->before_state&0x80));
670
671 if (!matched && test->_todo_wine)
672 {
673 failcount++;
674 todo_wine {
675 ok(matched, "%2d (%x/%x): %02x from %02x -> %02x "
676 "instead of %02x -> %02x\n", id, test->wVk, test->dwFlags,
677 t->wVk, ks1[t->wVk]&0x80, ks2[t->wVk]&0x80, t->before_state,
678 ~t->before_state&0x80);
679 }
680 } else {
681 ok(matched || t->optional, "%2d (%x/%x): %02x from %02x -> %02x "
682 "instead of %02x -> %02x\n", id, test->wVk, test->dwFlags,
683 t->wVk, ks1[t->wVk]&0x80, ks2[t->wVk]&0x80, t->before_state,
684 ~t->before_state&0x80);
685 }
686 ks2[t->wVk] = ks1[t->wVk]; /* clear the match */
687 t++;
688 }
689 for (i = 0; i < 256; i++)
690 if (ks2[i] != ks1[i] && test->_todo_wine)
691 {
692 failcount++;
693 todo_wine
694 ok(FALSE, "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
695 id, test->wVk, test->dwFlags, i, ks1[i], ks2[i]);
696 }
697 else
698 ok(ks2[i] == ks1[i], "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
699 id, test->wVk, test->dwFlags, i, ks1[i], ks2[i]);
700
701 while (expected->message && actual_cnt < sent_messages_cnt)
702 {
703 const struct message *actual = &sent_messages[actual_cnt];
704
705 if (expected->message == actual->message)
706 {
707 ok((expected->flags & hook) == (actual->flags & hook),
708 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
709 id, test->wVk, test->dwFlags, expected->message);
710
711 if (expected->flags & wparam)
712 {
713 if (expected->wParam != actual->wParam && test->_todo_wine)
714 {
715 failcount++;
716 todo_wine
717 ok(FALSE, "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
718 id, test->wVk, test->dwFlags, expected->message, expected->wParam, actual->wParam);
719 }
720 else
721 ok(expected->wParam == actual->wParam,
722 "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
723 id, test->wVk, test->dwFlags, expected->message, expected->wParam, actual->wParam);
724 }
725 if (expected->flags & lparam)
726 {
727 if (expected->lParam != actual->lParam && test->_todo_wine)
728 {
729 failcount++;
730 todo_wine
731 ok(FALSE, "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
732 id, test->wVk, test->dwFlags, expected->message, expected->lParam, actual->lParam);
733 }
734 else
735 ok(expected->lParam == actual->lParam,
736 "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
737 id, test->wVk, test->dwFlags, expected->message, expected->lParam, actual->lParam);
738 }
739 }
740 else if (expected->flags & optional)
741 {
742 expected++;
743 continue;
744 }
745 else if (test->_todo_wine)
746 {
747 failcount++;
748 todo_wine
749 ok(FALSE,
750 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
751 id, test->wVk, test->dwFlags, expected->message, actual->message);
752 }
753 else
754 ok(FALSE,
755 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
756 id, test->wVk, test->dwFlags, expected->message, actual->message);
757
758 actual_cnt++;
759 expected++;
760 }
761 /* skip all optional trailing messages */
762 while (expected->message && (expected->flags & optional))
763 expected++;
764
765
766 if (expected->message || actual_cnt < sent_messages_cnt)
767 {
768 if (test->_todo_wine)
769 {
770 failcount++;