5f8d68c4da75f8ab02f8faf42de77282ace6c11a
[reactos.git] / rostests / winetests / user32 / input.c
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 struct {
64 LONG last_key_down;
65 LONG last_key_up;
66 LONG last_syskey_down;
67 LONG last_syskey_up;
68 LONG last_char;
69 LONG last_syschar;
70 LONG last_hook_down;
71 LONG last_hook_up;
72 LONG last_hook_syskey_down;
73 LONG last_hook_syskey_up;
74 BOOL expect_alt;
75 BOOL sendinput_broken;
76 } key_status;
77
78 static UINT (WINAPI *pSendInput) (UINT, INPUT*, size_t);
79 static int (WINAPI *pGetMouseMovePointsEx) (UINT, LPMOUSEMOVEPOINT, LPMOUSEMOVEPOINT, int, DWORD);
80
81 #define MAXKEYEVENTS 12
82 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
83 and only one message */
84
85 /* keyboard message names, sorted as their value */
86 static const char *MSGNAME[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
87 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
88
89 /* keyevents, add more as needed */
90 typedef enum KEVtag
91 { ALTDOWN = 1, ALTUP, XDOWN, XUP, SHIFTDOWN, SHIFTUP, CTRLDOWN, CTRLUP } KEV;
92 /* matching VK's */
93 static const int GETVKEY[]={0, VK_MENU, VK_MENU, 'X', 'X', VK_SHIFT, VK_SHIFT, VK_CONTROL, VK_CONTROL};
94 /* matching scan codes */
95 static const int GETSCAN[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
96 /* matching updown events */
97 static const int GETFLAGS[]={0, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP};
98 /* matching descriptions */
99 static const char *getdesc[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
100
101 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
102 typedef struct
103 {
104 DWORD type;
105 union
106 {
107 MOUSEINPUT mi;
108 KEYBDINPUT ki;
109 HARDWAREINPUT hi;
110 } u;
111 } TEST_INPUT;
112
113 #define ADDTOINPUTS(kev) \
114 inputs[evtctr].type = INPUT_KEYBOARD; \
115 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
116 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
117 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETFLAGS[ kev]; \
118 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
119 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
120 if( kev) evtctr++;
121
122 typedef struct {
123 UINT message;
124 WPARAM wParam;
125 LPARAM lParam;
126 } KMSG;
127
128 /*******************************************
129 * add new test sets here
130 * the software will make all combinations of the
131 * keyevent defined here
132 */
133 static const struct {
134 int nrkev;
135 KEV keydwn[MAXKEYEVENTS];
136 KEV keyup[MAXKEYEVENTS];
137 } testkeyset[]= {
138 { 2, { ALTDOWN, XDOWN }, { ALTUP, XUP}},
139 { 3, { ALTDOWN, XDOWN , SHIFTDOWN}, { ALTUP, XUP, SHIFTUP}},
140 { 3, { ALTDOWN, XDOWN , CTRLDOWN}, { ALTUP, XUP, CTRLUP}},
141 { 3, { SHIFTDOWN, XDOWN , CTRLDOWN}, { SHIFTUP, XUP, CTRLUP}},
142 { 0 } /* mark the end */
143 };
144
145 /**********************adapted from input.c **********************************/
146
147 static BYTE InputKeyStateTable[256];
148 static BYTE AsyncKeyStateTable[256];
149 static BYTE TrackSysKey = 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
150 or a WM_KEYUP message */
151
152 static void init_function_pointers(void)
153 {
154 HMODULE hdll = GetModuleHandleA("user32");
155
156 #define GET_PROC(func) \
157 p ## func = (void*)GetProcAddress(hdll, #func); \
158 if(!p ## func) \
159 trace("GetProcAddress(%s) failed\n", #func);
160
161 GET_PROC(SendInput)
162 GET_PROC(GetMouseMovePointsEx)
163
164 #undef GET_PROC
165 }
166
167 static int KbdMessage( KEV kev, WPARAM *pwParam, LPARAM *plParam )
168 {
169 UINT message;
170 int VKey = GETVKEY[kev];
171 WORD flags;
172
173 flags = LOBYTE(GETSCAN[kev]);
174 if (GETFLAGS[kev] & KEYEVENTF_EXTENDEDKEY) flags |= KF_EXTENDED;
175
176 if (GETFLAGS[kev] & KEYEVENTF_KEYUP )
177 {
178 message = WM_KEYUP;
179 if( (InputKeyStateTable[VK_MENU] & 0x80) && (
180 (VKey == VK_MENU) || (VKey == VK_CONTROL) ||
181 !(InputKeyStateTable[VK_CONTROL] & 0x80))) {
182 if( TrackSysKey == VK_MENU || /* <ALT>-down/<ALT>-up sequence */
183 (VKey != VK_MENU)) /* <ALT>-down...<something else>-up */
184 message = WM_SYSKEYUP;
185 TrackSysKey = 0;
186 }
187 InputKeyStateTable[VKey] &= ~0x80;
188 flags |= KF_REPEAT | KF_UP;
189 }
190 else
191 {
192 if (InputKeyStateTable[VKey] & 0x80) flags |= KF_REPEAT;
193 if (!(InputKeyStateTable[VKey] & 0x80)) InputKeyStateTable[VKey] ^= 0x01;
194 InputKeyStateTable[VKey] |= 0x80;
195 AsyncKeyStateTable[VKey] |= 0x80;
196
197 message = WM_KEYDOWN;
198 if( (InputKeyStateTable[VK_MENU] & 0x80) &&
199 !(InputKeyStateTable[VK_CONTROL] & 0x80)) {
200 message = WM_SYSKEYDOWN;
201 TrackSysKey = VKey;
202 }
203 }
204
205 if (InputKeyStateTable[VK_MENU] & 0x80) flags |= KF_ALTDOWN;
206
207 if( plParam) *plParam = MAKELPARAM( 1, flags );
208 if( pwParam) *pwParam = VKey;
209 return message;
210 }
211
212 /****************************** end copy input.c ****************************/
213
214 /*
215 * . prepare the keyevents for SendInputs
216 * . calculate the "expected" messages
217 * . Send the events to our window
218 * . retrieve the messages from the input queue
219 * . verify
220 */
221 static BOOL do_test( HWND hwnd, int seqnr, const KEV td[] )
222 {
223 INPUT inputs[MAXKEYEVENTS];
224 KMSG expmsg[MAXKEYEVENTS];
225 MSG msg;
226 char buf[100];
227 UINT evtctr=0;
228 int kmctr, i;
229
230 buf[0]='\0';
231 TrackSysKey=0; /* see input.c */
232 for( i = 0; i < MAXKEYEVENTS; i++) {
233 ADDTOINPUTS(td[i])
234 strcat(buf, getdesc[td[i]]);
235 if(td[i])
236 expmsg[i].message = KbdMessage(td[i], &(expmsg[i].wParam), &(expmsg[i].lParam));
237 else
238 expmsg[i].message = 0;
239 }
240 for( kmctr = 0; kmctr < MAXKEYEVENTS && expmsg[kmctr].message; kmctr++)
241 ;
242 ok( evtctr <= MAXKEYEVENTS, "evtctr is above MAXKEYEVENTS\n" );
243 if( evtctr != pSendInput(evtctr, &inputs[0], sizeof(INPUT)))
244 ok (FALSE, "SendInput failed to send some events\n");
245 i = 0;
246 if (winetest_debug > 1)
247 trace("======== key stroke sequence #%d: %s =============\n",
248 seqnr + 1, buf);
249 while( PeekMessageA(&msg,hwnd,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE) ) {
250 if (winetest_debug > 1)
251 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i,
252 MSGNAME[msg.message - WM_KEYFIRST], msg.wParam, msg.lParam, msg.time);
253 if( i < kmctr ) {
254 ok( msg.message == expmsg[i].message &&
255 msg.wParam == expmsg[i].wParam &&
256 msg.lParam == expmsg[i].lParam,
257 "%u/%u: wrong message %x/%08lx/%08lx expected %s/%08lx/%08lx\n",
258 seqnr, i, msg.message, msg.wParam, msg.lParam,
259 MSGNAME[(expmsg[i]).message - WM_KEYFIRST], expmsg[i].wParam, expmsg[i].lParam );
260 }
261 i++;
262 }
263 if (winetest_debug > 1)
264 trace("%d messages retrieved\n", i);
265 if (!i && kmctr)
266 {
267 skip( "simulated keyboard input doesn't work\n" );
268 return FALSE;
269 }
270 ok( i == kmctr, "message count is wrong: got %d expected: %d\n", i, kmctr);
271 return TRUE;
272 }
273
274 /* test all combinations of the specified key events */
275 static BOOL TestASet( HWND hWnd, int nrkev, const KEV kevdwn[], const KEV kevup[] )
276 {
277 int i,j,k,l,m,n;
278 static int count=0;
279 KEV kbuf[MAXKEYEVENTS];
280 assert( nrkev==2 || nrkev==3);
281 for(i=0;i<MAXKEYEVENTS;i++) kbuf[i]=0;
282 /* two keys involved gives 4 test cases */
283 if(nrkev==2) {
284 for(i=0;i<nrkev;i++) {
285 for(j=0;j<nrkev;j++) {
286 kbuf[0] = kevdwn[i];
287 kbuf[1] = kevdwn[1-i];
288 kbuf[2] = kevup[j];
289 kbuf[3] = kevup[1-j];
290 if (!do_test( hWnd, count++, kbuf)) return FALSE;
291 }
292 }
293 }
294 /* three keys involved gives 36 test cases */
295 if(nrkev==3){
296 for(i=0;i<nrkev;i++){
297 for(j=0;j<nrkev;j++){
298 if(j==i) continue;
299 for(k=0;k<nrkev;k++){
300 if(k==i || k==j) continue;
301 for(l=0;l<nrkev;l++){
302 for(m=0;m<nrkev;m++){
303 if(m==l) continue;
304 for(n=0;n<nrkev;n++){
305 if(n==l ||n==m) continue;
306 kbuf[0] = kevdwn[i];
307 kbuf[1] = kevdwn[j];
308 kbuf[2] = kevdwn[k];
309 kbuf[3] = kevup[l];
310 kbuf[4] = kevup[m];
311 kbuf[5] = kevup[n];
312 if (!do_test( hWnd, count++, kbuf)) return FALSE;
313 }
314 }
315 }
316 }
317 }
318 }
319 }
320 return TRUE;
321 }
322
323 /* test each set specified in the global testkeyset array */
324 static void TestSysKeys( HWND hWnd)
325 {
326 int i;
327 for(i=0; testkeyset[i].nrkev;i++)
328 if (!TestASet( hWnd, testkeyset[i].nrkev, testkeyset[i].keydwn, testkeyset[i].keyup)) break;
329 }
330
331 static LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam,
332 LPARAM lParam )
333 {
334 return DefWindowProcA( hWnd, msg, wParam, lParam );
335 }
336
337 static void test_Input_whitebox(void)
338 {
339 MSG msg;
340 WNDCLASSA wclass;
341 HANDLE hInstance = GetModuleHandleA( NULL );
342
343 wclass.lpszClassName = "InputSysKeyTestClass";
344 wclass.style = CS_HREDRAW | CS_VREDRAW;
345 wclass.lpfnWndProc = WndProc;
346 wclass.hInstance = hInstance;
347 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
348 wclass.hCursor = LoadCursorA( NULL, (LPCSTR)IDC_ARROW );
349 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
350 wclass.lpszMenuName = 0;
351 wclass.cbClsExtra = 0;
352 wclass.cbWndExtra = 0;
353 RegisterClassA( &wclass );
354 /* create the test window that will receive the keystrokes */
355 hWndTest = CreateWindowA( wclass.lpszClassName, "InputSysKeyTest",
356 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
357 NULL, NULL, hInstance, NULL);
358 assert( hWndTest );
359 ShowWindow( hWndTest, SW_SHOW);
360 SetWindowPos( hWndTest, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
361 SetForegroundWindow( hWndTest );
362 UpdateWindow( hWndTest);
363
364 /* flush pending messages */
365 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
366
367 SetFocus( hWndTest );
368 TestSysKeys( hWndTest );
369 DestroyWindow(hWndTest);
370 }
371
372 static inline BOOL is_keyboard_message( UINT message )
373 {
374 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
375 }
376
377 static inline BOOL is_mouse_message( UINT message )
378 {
379 return (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST);
380 }
381
382 /* try to make sure pending X events have been processed before continuing */
383 static void empty_message_queue(void)
384 {
385 MSG msg;
386 int diff = 200;
387 int min_timeout = 50;
388 DWORD time = GetTickCount() + diff;
389
390 while (diff > 0)
391 {
392 if (MsgWaitForMultipleObjects(0, NULL, FALSE, min_timeout, QS_ALLINPUT) == WAIT_TIMEOUT) break;
393 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
394 {
395 if (is_keyboard_message(msg.message) || is_mouse_message(msg.message))
396 ok(msg.time != 0, "message %#x has time set to 0\n", msg.message);
397
398 TranslateMessage(&msg);
399 DispatchMessageA(&msg);
400 }
401 diff = time - GetTickCount();
402 }
403 }
404
405 struct transition_s {
406 WORD wVk;
407 BYTE before_state;
408 BYTE optional;
409 };
410
411 typedef enum {
412 sent=0x1,
413 posted=0x2,
414 parent=0x4,
415 wparam=0x8,
416 lparam=0x10,
417 defwinproc=0x20,
418 beginpaint=0x40,
419 optional=0x80,
420 hook=0x100,
421 winevent_hook=0x200
422 } msg_flags_t;
423
424 struct message {
425 UINT message; /* the WM_* code */
426 msg_flags_t flags; /* message props */
427 WPARAM wParam; /* expected value of wParam */
428 LPARAM lParam; /* expected value of lParam */
429 };
430
431 static const struct sendinput_test_s {
432 WORD wVk;
433 DWORD dwFlags;
434 BOOL _todo_wine;
435 struct transition_s expected_transitions[MAXKEYEVENTS+1];
436 struct message expected_messages[MAXKEYMESSAGES+1];
437 } sendinput_test[] = {
438 /* test ALT+F */
439 /* 0 */
440 {VK_LMENU, 0, FALSE, {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
441 {{WM_SYSKEYDOWN, hook|wparam, VK_LMENU}, {WM_SYSKEYDOWN}, {0}}},
442 {'F', 0, FALSE, {{'F', 0x00}, {0}},
443 {{WM_SYSKEYDOWN, hook}, {WM_SYSKEYDOWN},
444 {WM_SYSCHAR},
445 {WM_SYSCOMMAND}, {0}}},
446 {'F', KEYEVENTF_KEYUP, FALSE, {{'F', 0x80}, {0}},
447 {{WM_SYSKEYUP, hook}, {WM_SYSKEYUP}, {0}}},
448 {VK_LMENU, KEYEVENTF_KEYUP, FALSE, {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
449 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
450
451 /* test CTRL+O */
452 /* 4 */
453 {VK_LCONTROL, 0, FALSE, {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
454 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
455 {'O', 0, FALSE, {{'O', 0x00}, {0}},
456 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {WM_CHAR}, {0}}},
457 {'O', KEYEVENTF_KEYUP, FALSE, {{'O', 0x80}, {0}},
458 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
459 {VK_LCONTROL, KEYEVENTF_KEYUP, FALSE, {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
460 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
461
462 /* test ALT+CTRL+X */
463 /* 8 */
464 {VK_LMENU, 0, FALSE, {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
465 {{WM_SYSKEYDOWN, hook}, {WM_SYSKEYDOWN}, {0}}},
466 {VK_LCONTROL, 0, FALSE, {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
467 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
468 {'X', 0, FALSE, {{'X', 0x00}, {0}},
469 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
470 {'X', KEYEVENTF_KEYUP, FALSE, {{'X', 0x80}, {0}},
471 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
472 {VK_LCONTROL, KEYEVENTF_KEYUP, FALSE, {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
473 {{WM_SYSKEYUP, hook}, {WM_SYSKEYUP}, {0}}},
474 {VK_LMENU, KEYEVENTF_KEYUP, FALSE, {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
475 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
476
477 /* test SHIFT+A */
478 /* 14 */
479 {VK_LSHIFT, 0, FALSE, {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
480 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
481 {'A', 0, FALSE, {{'A', 0x00}, {0}},
482 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {WM_CHAR}, {0}}},
483 {'A', KEYEVENTF_KEYUP, FALSE, {{'A', 0x80}, {0}},
484 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
485 {VK_LSHIFT, KEYEVENTF_KEYUP, FALSE, {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
486 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
487 /* test L-SHIFT & R-SHIFT: */
488 /* RSHIFT == LSHIFT */
489 /* 18 */
490 {VK_RSHIFT, 0, FALSE,
491 /* recent windows versions (>= w2k3) correctly report an RSHIFT transition */
492 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00, TRUE}, {VK_RSHIFT, 0x00, TRUE}, {0}},
493 {{WM_KEYDOWN, hook|wparam, VK_RSHIFT},
494 {WM_KEYDOWN}, {0}}},
495 {VK_RSHIFT, KEYEVENTF_KEYUP, FALSE,
496 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80, TRUE}, {VK_RSHIFT, 0x80, TRUE}, {0}},
497 {{WM_KEYUP, hook, hook|wparam, VK_RSHIFT},
498 {WM_KEYUP}, {0}}},
499
500 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
501 /* 20 */
502 {VK_LSHIFT, KEYEVENTF_EXTENDEDKEY, FALSE,
503 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
504 {{WM_KEYDOWN, hook|wparam|lparam, VK_LSHIFT, LLKHF_EXTENDED},
505 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
506 {VK_LSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
507 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
508 {{WM_KEYUP, hook|wparam|lparam, VK_LSHIFT, LLKHF_UP|LLKHF_EXTENDED},
509 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
510 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
511 /* 22 */
512 {VK_RSHIFT, KEYEVENTF_EXTENDEDKEY, FALSE,
513 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
514 {{WM_KEYDOWN, hook|wparam|lparam, VK_RSHIFT, LLKHF_EXTENDED},
515 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
516 {VK_RSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
517 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
518 {{WM_KEYUP, hook|wparam|lparam, VK_RSHIFT, LLKHF_UP|LLKHF_EXTENDED},
519 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
520
521 /* Note about wparam for hook with generic key (VK_SHIFT, VK_CONTROL, VK_MENU):
522 win2k - sends to hook whatever we generated here
523 winXP+ - Attempts to convert key to L/R key but not always correct
524 */
525 /* SHIFT == LSHIFT */
526 /* 24 */
527 {VK_SHIFT, 0, FALSE,
528 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
529 {{WM_KEYDOWN, hook/* |wparam */|lparam, VK_SHIFT, 0},
530 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
531 {VK_SHIFT, KEYEVENTF_KEYUP, FALSE,
532 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
533 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_SHIFT, LLKHF_UP},
534 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
535 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
536 /* 26 */
537 {VK_SHIFT, KEYEVENTF_EXTENDEDKEY, FALSE,
538 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
539 {{WM_KEYDOWN, hook/*|wparam*/|lparam, VK_SHIFT, LLKHF_EXTENDED},
540 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
541 {VK_SHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
542 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
543 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_SHIFT, LLKHF_UP|LLKHF_EXTENDED},
544 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
545
546 /* test L-CONTROL & R-CONTROL: */
547 /* RCONTROL == LCONTROL */
548 /* 28 */
549 {VK_RCONTROL, 0, FALSE,
550 {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
551 {{WM_KEYDOWN, hook|wparam, VK_RCONTROL},
552 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, 0}, {0}}},
553 {VK_RCONTROL, KEYEVENTF_KEYUP, FALSE,
554 {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
555 {{WM_KEYUP, hook|wparam, VK_RCONTROL},
556 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP}, {0}}},
557 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
558 /* 30 */
559 {VK_LCONTROL, KEYEVENTF_EXTENDEDKEY, FALSE,
560 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
561 {{WM_KEYDOWN, hook|wparam|lparam, VK_LCONTROL, LLKHF_EXTENDED},
562 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
563 {VK_LCONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
564 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
565 {{WM_KEYUP, hook|wparam|lparam, VK_LCONTROL, LLKHF_UP|LLKHF_EXTENDED},
566 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
567 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
568 /* 32 */
569 {VK_RCONTROL, KEYEVENTF_EXTENDEDKEY, FALSE,
570 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
571 {{WM_KEYDOWN, hook|wparam|lparam, VK_RCONTROL, LLKHF_EXTENDED},
572 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
573 {VK_RCONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
574 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
575 {{WM_KEYUP, hook|wparam|lparam, VK_RCONTROL, LLKHF_UP|LLKHF_EXTENDED},
576 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
577 /* CONTROL == LCONTROL */
578 /* 34 */
579 {VK_CONTROL, 0, FALSE,
580 {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
581 {{WM_KEYDOWN, hook/*|wparam, VK_CONTROL*/},
582 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, 0}, {0}}},
583 {VK_CONTROL, KEYEVENTF_KEYUP, FALSE,
584 {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
585 {{WM_KEYUP, hook/*|wparam, VK_CONTROL*/},
586 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP}, {0}}},
587 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
588 /* 36 */
589 {VK_CONTROL, KEYEVENTF_EXTENDEDKEY, FALSE,
590 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
591 {{WM_KEYDOWN, hook/*|wparam*/|lparam, VK_CONTROL, LLKHF_EXTENDED},
592 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
593 {VK_CONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
594 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
595 {{WM_KEYUP, hook/*|wparam*/|lparam, VK_CONTROL, LLKHF_UP|LLKHF_EXTENDED},
596 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
597
598 /* test L-MENU & R-MENU: */
599 /* RMENU == LMENU */
600 /* 38 */
601 {VK_RMENU, 0, FALSE,
602 {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {VK_CONTROL, 0x00, 1}, {VK_LCONTROL, 0x01, 1}, {0}},
603 {{WM_SYSKEYDOWN, hook|wparam|optional, VK_LCONTROL},
604 {WM_SYSKEYDOWN, hook|wparam, VK_RMENU},
605 {WM_KEYDOWN, wparam|lparam|optional, VK_CONTROL, 0},
606 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0}, {0}}},
607 {VK_RMENU, KEYEVENTF_KEYUP, TRUE,
608 {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {VK_CONTROL, 0x81, 1}, {VK_LCONTROL, 0x80, 1}, {0}},
609 {{WM_KEYUP, hook|wparam|optional, VK_LCONTROL},
610 {WM_KEYUP, hook|wparam, VK_RMENU},
611 {WM_SYSKEYUP, wparam|lparam|optional, VK_CONTROL, KF_UP},
612 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP},
613 {WM_SYSCOMMAND, optional}, {0}}},
614 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
615 /* 40 */
616 {VK_LMENU, KEYEVENTF_EXTENDEDKEY, FALSE,
617 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
618 {{WM_SYSKEYDOWN, hook|wparam|lparam, VK_LMENU, LLKHF_EXTENDED},
619 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
620 {VK_LMENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, TRUE,
621 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
622 {{WM_KEYUP, hook|wparam|lparam, VK_LMENU, LLKHF_UP|LLKHF_EXTENDED},
623 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
624 {WM_SYSCOMMAND}, {0}}},
625 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
626 /* 42 */
627 {VK_RMENU, KEYEVENTF_EXTENDEDKEY, FALSE,
628 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {VK_CONTROL, 0x00, 1}, {VK_LCONTROL, 0x01, 1}, {0}},
629 {{WM_SYSKEYDOWN, hook|wparam|lparam|optional, VK_LCONTROL, 0},
630 {WM_SYSKEYDOWN, hook|wparam|lparam, VK_RMENU, LLKHF_EXTENDED},
631 {WM_KEYDOWN, wparam|lparam|optional, VK_CONTROL, 0},
632 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
633 {VK_RMENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, TRUE,
634 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {VK_CONTROL, 0x81, 1}, {VK_LCONTROL, 0x80, 1}, {0}},
635 {{WM_KEYUP, hook|wparam|lparam|optional, VK_LCONTROL, LLKHF_UP},
636 {WM_KEYUP, hook|wparam|lparam, VK_RMENU, LLKHF_UP|LLKHF_EXTENDED},
637 {WM_SYSKEYUP, wparam|lparam|optional, VK_CONTROL, KF_UP},
638 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
639 {WM_SYSCOMMAND, optional}, {0}}},
640 /* MENU == LMENU */
641 /* 44 */
642 {VK_MENU, 0, FALSE,
643 {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
644 {{WM_SYSKEYDOWN, hook/*|wparam, VK_MENU*/},
645 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0}, {0}}},
646 {VK_MENU, KEYEVENTF_KEYUP, TRUE,
647 {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
648 {{WM_KEYUP, hook/*|wparam, VK_MENU*/},
649 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP},
650 {WM_SYSCOMMAND}, {0}}},
651 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
652 /* 46 */
653 {VK_MENU, KEYEVENTF_EXTENDEDKEY, FALSE,
654 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {VK_CONTROL, 0x00, 1}, {VK_LCONTROL, 0x01, 1}, {0}},
655 {{WM_SYSKEYDOWN, hook|wparam|lparam|optional, VK_CONTROL, 0},
656 {WM_SYSKEYDOWN, hook/*|wparam*/|lparam, VK_MENU, LLKHF_EXTENDED},
657 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
658 {VK_MENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, TRUE,
659 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {VK_CONTROL, 0x81, 1}, {VK_LCONTROL, 0x80, 1}, {0}},
660 {{WM_KEYUP, hook|wparam|lparam|optional, VK_CONTROL, LLKHF_UP},
661 {WM_KEYUP, hook/*|wparam*/|lparam, VK_MENU, LLKHF_UP|LLKHF_EXTENDED},
662 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
663 {WM_SYSCOMMAND}, {0}}},
664
665 /* test LSHIFT & RSHIFT */
666 /* 48 */
667 {VK_LSHIFT, 0, FALSE,
668 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
669 {{WM_KEYDOWN, hook|wparam|lparam, VK_LSHIFT, 0},
670 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
671 {VK_RSHIFT, KEYEVENTF_EXTENDEDKEY, FALSE,
672 {{VK_RSHIFT, 0x00}, {0}},
673 {{WM_KEYDOWN, hook|wparam|lparam, VK_RSHIFT, LLKHF_EXTENDED},
674 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
675 {VK_RSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, FALSE,
676 {{VK_RSHIFT, 0x80}, {0}},
677 {{WM_KEYUP, hook|wparam|lparam, VK_RSHIFT, LLKHF_UP|LLKHF_EXTENDED},
678 {WM_KEYUP, optional}, {0}}},
679 {VK_LSHIFT, KEYEVENTF_KEYUP, FALSE,
680 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
681 {{WM_KEYUP, hook|wparam, VK_LSHIFT},
682 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
683
684 {0, 0, FALSE, {{0}}, {{0}}} /* end */
685 };
686
687 static struct message sent_messages[MAXKEYMESSAGES];
688 static UINT sent_messages_cnt;
689
690 /* Verify that only specified key state transitions occur */
691 static void compare_and_check(int id, BYTE *ks1, BYTE *ks2, const struct sendinput_test_s *test)
692 {
693 int i, failcount = 0;
694 const struct transition_s *t = test->expected_transitions;
695 UINT actual_cnt = 0;
696 const struct message *expected = test->expected_messages;
697
698 while (t->wVk) {
699 BOOL matched = ((ks1[t->wVk]&0x80) == (t->before_state&0x80)
700 && (ks2[t->wVk]&0x80) == (~t->before_state&0x80));
701
702 if (!matched && !t->optional && test->_todo_wine)
703 {
704 failcount++;
705 todo_wine {
706 ok(matched, "%2d (%x/%x): %02x from %02x -> %02x "
707 "instead of %02x -> %02x\n", id, test->wVk, test->dwFlags,
708 t->wVk, ks1[t->wVk]&0x80, ks2[t->wVk]&0x80, t->before_state,
709 ~t->before_state&0x80);
710 }
711 } else {
712 ok(matched || t->optional, "%2d (%x/%x): %02x from %02x -> %02x "
713 "instead of %02x -> %02x\n", id, test->wVk, test->dwFlags,
714 t->wVk, ks1[t->wVk]&0x80, ks2[t->wVk]&0x80, t->before_state,
715 ~t->before_state&0x80);
716 }
717 ks2[t->wVk] = ks1[t->wVk]; /* clear the match */
718 t++;
719 }
720 for (i = 0; i < 256; i++)
721 if (ks2[i] != ks1[i] && test->_todo_wine)
722 {
723 failcount++;
724 todo_wine
725 ok(FALSE, "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
726 id, test->wVk, test->dwFlags, i, ks1[i], ks2[i]);
727 }
728 else
729 ok(ks2[i] == ks1[i], "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
730 id, test->wVk, test->dwFlags, i, ks1[i], ks2[i]);
731
732 while (expected->message && actual_cnt < sent_messages_cnt)
733 {
734 const struct message *actual = &sent_messages[actual_cnt];
735
736 if (expected->message == actual->message)
737 {
738 if (expected->flags & wparam)
739 {
740 if ((expected->flags & optional) && (expected->wParam != actual->wParam))
741 {
742 expected++;
743 continue;
744 }
745 if (expected->wParam != actual->wParam && test->_todo_wine)
746 {
747 failcount++;
748 todo_wine
749 ok(FALSE, "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
750 id, test->wVk, test->dwFlags, expected->message, expected->wParam, actual->wParam);
751 }
752 else
753 ok(expected->wParam == actual->wParam,
754 "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
755 id, test->wVk, test->dwFlags, expected->message, expected->wParam, actual->wParam);
756 }
757 if (expected->flags & lparam)
758 {
759 if (expected->lParam != actual->lParam && test->_todo_wine)
760 {
761 failcount++;
762 todo_wine
763 ok(FALSE, "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
764 id, test->wVk, test->dwFlags, expected->message, expected->lParam, actual->lParam);
765 }
766 else
767 ok(expected->lParam == actual->lParam,
768 "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
769 id, test->wVk, test->dwFlags, expected->message, expected->lParam, actual->lParam);
770 }
771 ok((expected->flags & hook) == (actual->flags & hook),
772 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
773 id, test->wVk, test->dwFlags, expected->message);
774
775 }
776 else if (expected->flags & optional)
777 {
778 expected++;
779 continue;
780 }
781 /* NT4 doesn't send SYSKEYDOWN/UP to hooks, only KEYDOWN/UP */
782 else if ((expected->flags & hook) &&
783 (expected->message == WM_SYSKEYDOWN || expected->message == WM_SYSKEYUP) &&
784 (actual->message == expected->message - 4))
785 {
786 ok((expected->flags & hook) == (actual->flags & hook),
787 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
788 id, test->wVk, test->dwFlags, expected->message);
789 }
790 /* For VK_RMENU, at least localized Win2k/XP sends KEYDOWN/UP
791 * instead of SYSKEYDOWN/UP to the WNDPROC */
792 else if (test->wVk == VK_RMENU && !(expected->flags & hook) &&
793 (expected->message == WM_SYSKEYDOWN || expected->message == WM_SYSKEYUP) &&
794 (actual->message == expected->message - 4))
795 {
796 ok(expected->wParam == actual->wParam && expected->lParam == actual->lParam,
797 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
798 id, test->wVk, test->dwFlags, expected->message, actual->message);
799 }
800 else if (test->_todo_wine)
801 {
802 failcount++;
803 todo_wine
804 ok(FALSE,
805 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
806 id, test->wVk, test->dwFlags, expected->message, actual->message);
807 }
808 else
809 ok(FALSE,
810 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
811 id, test->wVk, test->dwFlags, expected->message, actual->message);
812
813 actual_cnt++;
814 expected++;
815 }
816 /* skip all optional trailing messages */
817 while (expected->message && (expected->flags & optional))
818 expected++;
819
820
821 if (expected->message || actual_cnt < sent_messages_cnt)
822 {
823 if (test->_todo_wine)
824 {
825 failcount++;
826 todo_wine
827 ok(FALSE, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
828 id, test->wVk, test->dwFlags, expected->message, sent_messages[actual_cnt].message);
829 }
830 else
831 ok(FALSE, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
832 id, test->wVk, test->dwFlags, expected->message, sent_messages[actual_cnt].message);
833 }
834
835 if( test->_todo_wine && !failcount) /* succeeded yet marked todo */
836 todo_wine
837 ok(TRUE, "%2d (%x/%x): marked \"todo_wine\" but succeeds\n", id, test->wVk, test->dwFlags);
838
839 sent_messages_cnt = 0;
840 }
841
842 /* WndProc2 checks that we get at least the messages specified */
843 static LRESULT CALLBACK WndProc2(HWND hWnd, UINT Msg, WPARAM wParam,
844 LPARAM lParam)
845 {
846 if (winetest_debug > 1) trace("MSG: %8x W:%8lx L:%8lx\n", Msg, wParam, lParam);
847
848 if (Msg != WM_PAINT &&
849 Msg != WM_NCPAINT &&
850 Msg != WM_SYNCPAINT &&
851 Msg != WM_ERASEBKGND &&
852 Msg != WM_NCHITTEST &&
853 Msg != WM_GETTEXT &&
854 Msg != WM_GETICON &&
855 Msg != WM_IME_SELECT &&
856 Msg != WM_DEVICECHANGE &&
857 Msg != WM_TIMECHANGE)
858 {
859 ok(sent_messages_cnt < MAXKEYMESSAGES, "Too many messages\n");
860 if (sent_messages_cnt < MAXKEYMESSAGES)
861 {
862 sent_messages[sent_messages_cnt].message = Msg;
863 sent_messages[sent_messages_cnt].flags = 0;
864 sent_messages[sent_messages_cnt].wParam = wParam;
865 sent_messages[sent_messages_cnt++].lParam = HIWORD(lParam) & (KF_UP|KF_EXTENDED);
866 }
867 }
868 return DefWindowProcA(hWnd, Msg, wParam, lParam);
869 }
870
871 static LRESULT CALLBACK hook_proc(int code, WPARAM wparam, LPARAM lparam)
872 {
873 KBDLLHOOKSTRUCT *hook_info = (KBDLLHOOKSTRUCT *)lparam;
874
875 if (code == HC_ACTION)
876 {
877 ok(sent_messages_cnt < MAXKEYMESSAGES, "Too many messages\n");
878 if (sent_messages_cnt < MAXKEYMESSAGES)
879 {
880 sent_messages[sent_messages_cnt].message = wparam;
881 sent_messages[sent_messages_cnt].flags = hook;
882 sent_messages[sent_messages_cnt].wParam = hook_info->vkCode;
883 sent_messages[sent_messages_cnt++].lParam = hook_info->flags & (LLKHF_UP|LLKHF_EXTENDED);
884 }
885
886 if(0) /* For some reason not stable on Wine */
887 {
888 if (wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN)
889 ok(!(GetAsyncKeyState(hook_info->vkCode) & 0x8000), "key %x should be up\n", hook_info->vkCode);
890 else if (wparam == WM_KEYUP || wparam == WM_SYSKEYUP)
891 ok(GetAsyncKeyState(hook_info->vkCode) & 0x8000, "key %x should be down\n", hook_info->vkCode);
892 }
893
894 if (winetest_debug > 1)
895 trace("Hook: w=%lx vk:%8x sc:%8x fl:%8x %lx\n", wparam,
896 hook_info->vkCode, hook_info->scanCode, hook_info->flags, hook_info->dwExtraInfo);
897 }
898 return CallNextHookEx( 0, code, wparam, lparam );
899 }
900 static void test_Input_blackbox(void)
901 {
902 TEST_INPUT i;
903 int ii;
904 BYTE ks1[256], ks2[256];
905 LONG_PTR prevWndProc;
906 HWND window;
907 HHOOK hook;
908
909 if (GetKeyboardLayout(0) != (HKL)(ULONG_PTR)0x04090409)
910 {
911 skip("Skipping Input_blackbox test on non-US keyboard\n");
912 return;
913 }
914 window = CreateWindowA("Static", NULL, WS_POPUP|WS_HSCROLL|WS_VSCROLL
915 |WS_VISIBLE, 0, 0, 200, 60, NULL, NULL,
916 NULL, NULL);
917 ok(window != NULL, "error: %d\n", (int) GetLastError());
918 SetWindowPos( window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
919 SetForegroundWindow( window );
920
921 if (!(hook = SetWindowsHookExA(WH_KEYBOARD_LL, hook_proc, GetModuleHandleA( NULL ), 0)))
922 {
923 DestroyWindow(window);
924 win_skip("WH_KEYBOARD_LL is not supported\n");
925 return;
926 }
927
928 /* must process all initial messages, otherwise X11DRV_KeymapNotify unsets
929 * key state set by SendInput(). */
930 empty_message_queue();
931
932 prevWndProc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR) WndProc2);
933 ok(prevWndProc != 0 || (prevWndProc == 0 && GetLastError() == 0),
934 "error: %d\n", (int) GetLastError());
935
936 i.type = INPUT_KEYBOARD;
937 i.u.ki.time = 0;
938 i.u.ki.dwExtraInfo = 0;
939
940 for (ii = 0; ii < sizeof(sendinput_test)/sizeof(struct sendinput_test_s)-1;
941 ii++) {
942 GetKeyboardState(ks1);
943 i.u.ki.wScan = ii+1 /* useful for debugging */;
944 i.u.ki.dwFlags = sendinput_test[ii].dwFlags;
945 i.u.ki.wVk = sendinput_test[ii].wVk;
946 pSendInput(1, (INPUT*)&i, sizeof(TEST_INPUT));
947 empty_message_queue();
948 GetKeyboardState(ks2);
949 if (!ii && sent_messages_cnt <= 1 && !memcmp( ks1, ks2, sizeof(ks1) ))
950 {
951 win_skip( "window doesn't receive the queued input\n" );
952 /* release the key */
953 i.u.ki.dwFlags |= KEYEVENTF_KEYUP;
954 pSendInput(1, (INPUT*)&i, sizeof(TEST_INPUT));
955 break;
956 }
957 compare_and_check(ii, ks1, ks2, &sendinput_test[ii]);
958 }
959
960 empty_message_queue();
961 DestroyWindow(window);
962 UnhookWindowsHookEx(hook);
963 }
964
965 static void reset_key_status(void)
966 {
967 key_status.last_key_down = -1;
968 key_status.last_key_up = -1;
969 key_status.last_syskey_down = -1;
970 key_status.last_syskey_up = -1;
971 key_status.last_char = -1;
972 key_status.last_syschar = -1;
973 key_status.last_hook_down = -1;
974 key_status.last_hook_up = -1;
975 key_status.last_hook_syskey_down = -1;
976 key_status.last_hook_syskey_up = -1;
977 key_status.expect_alt = FALSE;
978 key_status.sendinput_broken = FALSE;
979 }
980
981 static void test_unicode_keys(HWND hwnd, HHOOK hook)
982 {
983 TEST_INPUT inputs[2];
984 MSG msg;
985
986 /* init input data that never changes */
987 inputs[1].type = inputs[0].type = INPUT_KEYBOARD;
988 inputs[1].u.ki.dwExtraInfo = inputs[0].u.ki.dwExtraInfo = 0;
989 inputs[1].u.ki.time = inputs[0].u.ki.time = 0;
990
991 /* pressing & releasing a single unicode character */
992 inputs[0].u.ki.wVk = 0;
993 inputs[0].u.ki.wScan = 0x3c0;
994 inputs[0].u.ki.dwFlags = KEYEVENTF_UNICODE;
995
996 reset_key_status();
997 pSendInput(1, (INPUT*)inputs, sizeof(INPUT));
998 while(PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE)){
999 if(msg.message == WM_KEYDOWN && msg.wParam == VK_PACKET){
1000 TranslateMessage(&msg);
1001 }
1002 DispatchMessageW(&msg);
1003 }
1004 if(!key_status.sendinput_broken){
1005 ok(key_status.last_key_down == VK_PACKET,
1006 "Last keydown msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET, key_status.last_key_down);
1007 ok(key_status.last_char == 0x3c0,
1008 "Last char msg wparam should have been 0x3c0 (was: 0x%x)\n", key_status.last_char);
1009 if(hook)
1010 ok(key_status.last_hook_down == 0x3c0,
1011 "Last hookdown msg should have been 0x3c0, was: 0x%x\n", key_status.last_hook_down);
1012 }
1013
1014 inputs[1].u.ki.wVk = 0;
1015 inputs[1].u.ki.wScan = 0x3c0;
1016 inputs[1].u.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
1017
1018 reset_key_status();
1019 pSendInput(1, (INPUT*)(inputs+1), sizeof(INPUT));
1020 while(PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE)){
1021 if(msg.message == WM_KEYDOWN && msg.wParam == VK_PACKET){
1022 TranslateMessage(&msg);
1023 }
1024 DispatchMessageW(&msg);
1025 }
1026 if(!key_status.sendinput_broken){
1027 ok(key_status.last_key_up == VK_PACKET,
1028 "Last keyup msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET, key_status.last_key_up);
1029 if(hook)
1030 ok(key_status.last_hook_up == 0x3c0,
1031 "Last hookup msg should have been 0x3c0, was: 0x%x\n", key_status.last_hook_up);
1032 }
1033
1034 /* holding alt, pressing & releasing a unicode character, releasing alt */
1035 inputs[0].u.ki.wVk = VK_LMENU;
1036 inputs[0].u.ki.wScan = 0;
1037 inputs[0].u.ki.dwFlags = 0;
1038
1039 inputs[1].u.ki.wVk = 0;
1040 inputs[1].u.ki.wScan = 0x3041;
1041 inputs[1].u.ki.dwFlags = KEYEVENTF_UNICODE;
1042
1043 reset_key_status();
1044 key_status.expect_alt = TRUE;
1045 pSendInput(2, (INPUT*)inputs, sizeof(INPUT));
1046 while(PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE)){
1047 if(msg.message == WM_SYSKEYDOWN && msg.wParam == VK_PACKET){
1048 TranslateMessage(&msg);
1049 }
1050 DispatchMessageW(&msg);
1051 }
1052 if(!key_status.sendinput_broken){
1053 ok(key_status.last_syskey_down == VK_PACKET,
1054 "Last syskeydown msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET, key_status.last_syskey_down);
1055 ok(key_status.last_syschar == 0x3041,
1056 "Last syschar msg should have been 0x3041 (was: 0x%x)\n", key_status.last_syschar);
1057 if(hook)
1058 ok(key_status.last_hook_syskey_down == 0x3041,
1059 "Last hooksysdown msg should have been 0x3041, was: 0x%x\n", key_status.last_hook_syskey_down);
1060 }
1061
1062 inputs[1].u.ki.wVk = 0;
1063 inputs[1].u.ki.wScan = 0x3041;
1064 inputs[1].u.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
1065
1066 inputs[0].u.ki.wVk = VK_LMENU;
1067 inputs[0].u.ki.wScan = 0;
1068 inputs[0].u.ki.dwFlags = KEYEVENTF_KEYUP;
1069
1070 reset_key_status();
1071 key_status.expect_alt = TRUE;
1072 pSendInput(2, (INPUT*)inputs, sizeof(INPUT));
1073 while(PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE)){
1074 if(msg.message == WM_SYSKEYDOWN && msg.wParam == VK_PACKET){
1075 TranslateMessage(&msg);
1076 }
1077 DispatchMessageW(&msg);
1078 }
1079 if(!key_status.sendinput_broken){
1080 ok(key_status.last_key_up == VK_PACKET,
1081 "Last keyup msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET, key_status.last_key_up);
1082 if(hook)
1083 ok(key_status.last_hook_up == 0x3041,
1084 "Last hook up msg should have been 0x3041, was: 0x%x\n", key_status.last_hook_up);
1085 }
1086 }
1087
1088 static LRESULT CALLBACK unicode_wnd_proc( HWND hWnd, UINT msg, WPARAM wParam,
1089 LPARAM lParam )
1090 {
1091 switch(msg){
1092 case WM_KEYDOWN:
1093 key_status.last_key_down = wParam;
1094 break;
1095 case WM_SYSKEYDOWN:
1096 key_status.last_syskey_down = wParam;
1097 break;
1098 case WM_KEYUP:
1099 key_status.last_key_up = wParam;
1100 break;
1101 case WM_SYSKEYUP:
1102 key_status.last_syskey_up = wParam;
1103 break;
1104 case WM_CHAR:
1105 key_status.last_char = wParam;
1106 break;
1107 case WM_SYSCHAR:
1108 key_status.last_syschar = wParam;
1109 break;
1110 }
1111 return DefWindowProcW(hWnd, msg, wParam, lParam);
1112 }
1113
1114 static LRESULT CALLBACK llkbd_unicode_hook(int nCode, WPARAM wParam, LPARAM lParam)
1115 {
1116 if(nCode == HC_ACTION){
1117 LPKBDLLHOOKSTRUCT info = (LPKBDLLHOOKSTRUCT)lParam;
1118 if(!info->vkCode){
1119 key_status.sendinput_broken = TRUE;
1120 win_skip("SendInput doesn't support unicode on this platform\n");
1121 }else{
1122 if(key_status.expect_alt){
1123 ok(info->vkCode == VK_LMENU, "vkCode should have been VK_LMENU[0x%04x], was: 0x%x\n", VK_LMENU, info->vkCode);
1124 key_status.expect_alt = FALSE;
1125 }else
1126 ok(info->vkCode == VK_PACKET, "vkCode should have been VK_PACKET[0x%04x], was: 0x%x\n", VK_PACKET, info->vkCode);
1127 }
1128 switch(wParam){
1129 case WM_KEYDOWN:
1130 key_status.last_hook_down = info->scanCode;
1131 break;
1132 case WM_KEYUP:
1133 key_status.last_hook_up = info->scanCode;
1134 break;
1135 case WM_SYSKEYDOWN:
1136 key_status.last_hook_syskey_down = info->scanCode;
1137 break;
1138 case WM_SYSKEYUP:
1139 key_status.last_hook_syskey_up = info->scanCode;
1140 break;
1141 }
1142 }
1143 return CallNextHookEx(NULL, nCode, wParam, lParam);
1144 }
1145
1146 static void test_Input_unicode(void)
1147 {
1148 WCHAR classNameW[] = {'I','n','p','u','t','U','n','i','c','o','d','e',
1149 'K','e','y','T','e','s','t','C','l','a','s','s',0};
1150 WCHAR windowNameW[] = {'I','n','p','u','t','U','n','i','c','o','d','e',
1151 'K','e','y','T','e','s','t',0};
1152 MSG msg;
1153 WNDCLASSW wclass;
1154 HANDLE hInstance = GetModuleHandleW(NULL);
1155 HHOOK hook;
1156 HMODULE hModuleImm32;
1157 BOOL (WINAPI *pImmDisableIME)(DWORD);
1158
1159 wclass.lpszClassName = classNameW;
1160 wclass.style = CS_HREDRAW | CS_VREDRAW;
1161 wclass.lpfnWndProc = unicode_wnd_proc;
1162 wclass.hInstance = hInstance;
1163 wclass.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
1164 wclass.hCursor = LoadCursorW( NULL, (LPCWSTR)IDC_ARROW);
1165 wclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1166 wclass.lpszMenuName = 0;
1167 wclass.cbClsExtra = 0;
1168 wclass.cbWndExtra = 0;
1169 if(!RegisterClassW(&wclass)){
1170 win_skip("Unicode functions not supported\n");
1171 return;
1172 }
1173
1174 hModuleImm32 = LoadLibraryA("imm32.dll");
1175 if (hModuleImm32) {
1176 pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
1177 if (pImmDisableIME)
1178 pImmDisableIME(0);
1179 }
1180 pImmDisableIME = NULL;
1181 FreeLibrary(hModuleImm32);
1182
1183 /* create the test window that will receive the keystrokes */
1184 hWndTest = CreateWindowW(wclass.lpszClassName, windowNameW,
1185 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
1186 NULL, NULL, hInstance, NULL);
1187
1188 assert(hWndTest);
1189 assert(IsWindowUnicode(hWndTest));
1190
1191 hook = SetWindowsHookExW(WH_KEYBOARD_LL, llkbd_unicode_hook, GetModuleHandleW(NULL), 0);
1192 if(!hook)
1193 win_skip("unable to set WH_KEYBOARD_LL hook\n");
1194
1195 ShowWindow(hWndTest, SW_SHOW);
1196 SetWindowPos(hWndTest, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1197 SetForegroundWindow(hWndTest);
1198 UpdateWindow(hWndTest);
1199
1200 /* flush pending messages */
1201 while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageW(&msg);
1202
1203 SetFocus(hWndTest);
1204
1205 test_unicode_keys(hWndTest, hook);
1206
1207 if(hook)
1208 UnhookWindowsHookEx(hook);
1209 DestroyWindow(hWndTest);
1210 }
1211
1212 static void test_keynames(void)
1213 {
1214 int i, len;
1215 char buff[256];
1216
1217 for (i = 0; i < 512; i++)
1218 {
1219 strcpy(buff, "----");
1220 len = GetKeyNameTextA(i << 16, buff, sizeof(buff));
1221 ok(len || !buff[0], "%d: Buffer is not zeroed\n", i);
1222 }
1223 }
1224
1225 static POINT pt_old, pt_new;
1226 static BOOL clipped;
1227 #define STEP 3
1228
1229 static LRESULT CALLBACK hook_proc1( int code, WPARAM wparam, LPARAM lparam )
1230 {
1231 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
1232 POINT pt, pt1;
1233
1234 if (code == HC_ACTION)
1235 {
1236 /* This is our new cursor position */
1237 pt_new = hook->pt;
1238 /* Should return previous position */
1239 GetCursorPos(&pt);
1240 ok(pt.x == pt_old.x && pt.y == pt_old.y, "GetCursorPos: (%d,%d)\n", pt.x, pt.y);
1241
1242 /* Should set new position until hook chain is finished. */
1243 pt.x = pt_old.x + STEP;
1244 pt.y = pt_old.y + STEP;
1245 SetCursorPos(pt.x, pt.y);
1246 GetCursorPos(&pt1);
1247 if (clipped)
1248 ok(pt1.x == pt_old.x && pt1.y == pt_old.y, "Wrong set pos: (%d,%d)\n", pt1.x, pt1.y);
1249 else
1250 ok(pt1.x == pt.x && pt1.y == pt.y, "Wrong set pos: (%d,%d)\n", pt1.x, pt1.y);
1251 }
1252 return CallNextHookEx( 0, code, wparam, lparam );
1253 }
1254
1255 static LRESULT CALLBACK hook_proc2( int code, WPARAM wparam, LPARAM lparam )
1256 {
1257 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
1258 POINT pt;
1259
1260 if (code == HC_ACTION)
1261 {
1262 ok(hook->pt.x == pt_new.x && hook->pt.y == pt_new.y,
1263 "Wrong hook coords: (%d %d) != (%d,%d)\n", hook->pt.x, hook->pt.y, pt_new.x, pt_new.y);
1264
1265 /* Should match position set above */
1266 GetCursorPos(&pt);
1267 if (clipped)
1268 ok(pt.x == pt_old.x && pt.y == pt_old.y, "GetCursorPos: (%d,%d)\n", pt.x, pt.y);
1269 else
1270 ok(pt.x == pt_old.x +STEP && pt.y == pt_old.y +STEP, "GetCursorPos: (%d,%d)\n", pt.x, pt.y);
1271 }
1272 return CallNextHookEx( 0, code, wparam, lparam );
1273 }
1274
1275 static void test_mouse_ll_hook(void)
1276 {
1277 HWND hwnd;
1278 HHOOK hook1, hook2;
1279 POINT pt_org, pt;
1280 RECT rc;
1281
1282 GetCursorPos(&pt_org);
1283 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1284 10, 10, 200, 200, NULL, NULL, NULL, NULL);
1285 SetCursorPos(100, 100);
1286
1287 if (!(hook2 = SetWindowsHookExA(WH_MOUSE_LL, hook_proc2, GetModuleHandleA(0), 0)))
1288 {
1289 win_skip( "cannot set MOUSE_LL hook\n" );
1290 goto done;
1291 }
1292 hook1 = SetWindowsHookExA(WH_MOUSE_LL, hook_proc1, GetModuleHandleA(0), 0);
1293
1294 GetCursorPos(&pt_old);
1295 mouse_event(MOUSEEVENTF_MOVE, -STEP, 0, 0, 0);
1296 GetCursorPos(&pt_old);
1297 ok(pt_old.x == pt_new.x && pt_old.y == pt_new.y, "Wrong new pos: (%d,%d)\n", pt_old.x, pt_old.y);
1298 mouse_event(MOUSEEVENTF_MOVE, +STEP, 0, 0, 0);
1299 GetCursorPos(&pt_old);
1300 ok(pt_old.x == pt_new.x && pt_old.y == pt_new.y, "Wrong new pos: (%d,%d)\n", pt_old.x, pt_old.y);
1301 mouse_event(MOUSEEVENTF_MOVE, 0, -STEP, 0, 0);
1302 GetCursorPos(&pt_old);
1303 ok(pt_old.x == pt_new.x && pt_old.y == pt_new.y, "Wrong new pos: (%d,%d)\n", pt_old.x, pt_old.y);
1304 mouse_event(MOUSEEVENTF_MOVE, 0, +STEP, 0, 0);
1305 GetCursorPos(&pt_old);
1306 ok(pt_old.x == pt_new.x && pt_old.y == pt_new.y, "Wrong new pos: (%d,%d)\n", pt_old.x, pt_old.y);
1307
1308 SetRect(&rc, 50, 50, 151, 151);
1309 ClipCursor(&rc);
1310 clipped = TRUE;
1311
1312 SetCursorPos(40, 40);
1313 GetCursorPos(&pt_old);
1314 ok(pt_old.x == 50 && pt_old.y == 50, "Wrong new pos: (%d,%d)\n", pt_new.x, pt_new.y);
1315 SetCursorPos(160, 160);
1316 GetCursorPos(&pt_old);
1317 ok(pt_old.x == 150 && pt_old.y == 150, "Wrong new pos: (%d,%d)\n", pt_new.x, pt_new.y);
1318 mouse_event(MOUSEEVENTF_MOVE, +STEP, +STEP, 0, 0);
1319 GetCursorPos(&pt_old);
1320 ok(pt_old.x == 150 && pt_old.y == 150, "Wrong new pos: (%d,%d)\n", pt_new.x, pt_new.y);
1321
1322 clipped = FALSE;
1323 pt_new.x = pt_new.y = 150;
1324 ClipCursor(NULL);
1325 UnhookWindowsHookEx(hook1);
1326
1327 /* Now check that mouse buttons do not change mouse position
1328 if we don't have MOUSEEVENTF_MOVE flag specified. */
1329
1330 /* We reusing the same hook callback, so make it happy */
1331 pt_old.x = pt_new.x - STEP;
1332 pt_old.y = pt_new.y - STEP;
1333 mouse_event(MOUSEEVENTF_LEFTUP, 123, 456, 0, 0);
1334 GetCursorPos(&pt);
1335 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
1336 mouse_event(MOUSEEVENTF_RIGHTUP, 456, 123, 0, 0);
1337 GetCursorPos(&pt);
1338 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
1339
1340 mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, 123, 456, 0, 0);
1341 GetCursorPos(&pt);
1342 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
1343 mouse_event(MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE, 456, 123, 0, 0);
1344 GetCursorPos(&pt);
1345 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
1346
1347 UnhookWindowsHookEx(hook2);
1348 done:
1349 DestroyWindow(hwnd);
1350 SetCursorPos(pt_org.x, pt_org.y);
1351 }
1352
1353 static void test_GetMouseMovePointsEx(void)
1354 {
1355 #define BUFLIM 64
1356 #define MYERROR 0xdeadbeef
1357 int count, retval;
1358 MOUSEMOVEPOINT in;
1359 MOUSEMOVEPOINT out[200];
1360 POINT point;
1361
1362 /* Get a valid content for the input struct */
1363 if(!GetCursorPos(&point)) {
1364 win_skip("GetCursorPos() failed with error %u\n", GetLastError());
1365 return;
1366 }
1367 memset(&in, 0, sizeof(MOUSEMOVEPOINT));
1368 in.x = point.x;
1369 in.y = point.y;
1370
1371 /* test first parameter
1372 * everything different than sizeof(MOUSEMOVEPOINT)
1373 * is expected to fail with ERROR_INVALID_PARAMETER
1374 */
1375 SetLastError(MYERROR);
1376 retval = pGetMouseMovePointsEx(0, &in, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1377 if (retval == ERROR_INVALID_PARAMETER)
1378 {
1379 win_skip( "GetMouseMovePointsEx broken on WinME\n" );
1380 return;
1381 }
1382 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1383 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1384 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1385
1386 SetLastError(MYERROR);
1387 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)-1, &in, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1388 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1389 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1390 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1391
1392 SetLastError(MYERROR);
1393 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)+1, &in, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1394 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1395 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1396 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1397
1398 /* test second and third parameter
1399 */
1400 SetLastError(MYERROR);
1401 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), NULL, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1402 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1403 ok(GetLastError() == ERROR_NOACCESS || GetLastError() == MYERROR,
1404 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1405
1406 SetLastError(MYERROR);
1407 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, NULL, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1408 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1409 ok(ERROR_NOACCESS == GetLastError(),
1410 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1411
1412 SetLastError(MYERROR);
1413 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), NULL, NULL, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1414 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1415 ok(ERROR_NOACCESS == GetLastError(),
1416 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1417
1418 SetLastError(MYERROR);
1419 count = 0;
1420 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, NULL, count, GMMP_USE_DISPLAY_POINTS);
1421 if (retval == -1)
1422 ok(GetLastError() == ERROR_POINT_NOT_FOUND, "unexpected error %u\n", GetLastError());
1423 else
1424 ok(retval == count, "expected GetMouseMovePointsEx to succeed, got %d\n", retval);
1425
1426 /* test fourth parameter
1427 * a value higher than 64 is expected to fail with ERROR_INVALID_PARAMETER
1428 */
1429 SetLastError(MYERROR);
1430 count = -1;
1431 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, count, GMMP_USE_DISPLAY_POINTS);
1432 ok(retval == count, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1433 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1434 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1435
1436 SetLastError(MYERROR);
1437 count = 0;
1438 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, count, GMMP_USE_DISPLAY_POINTS);
1439 if (retval == -1)
1440 ok(GetLastError() == ERROR_POINT_NOT_FOUND, "unexpected error %u\n", GetLastError());
1441 else
1442 ok(retval == count, "expected GetMouseMovePointsEx to succeed, got %d\n", retval);
1443
1444 SetLastError(MYERROR);
1445 count = BUFLIM;
1446 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, count, GMMP_USE_DISPLAY_POINTS);
1447 if (retval == -1)
1448 ok(GetLastError() == ERROR_POINT_NOT_FOUND, "unexpected error %u\n", GetLastError());
1449 else
1450 ok((0 <= retval) && (retval <= count), "expected GetMouseMovePointsEx to succeed, got %d\n", retval);
1451
1452 SetLastError(MYERROR);
1453 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, BUFLIM+1, GMMP_USE_DISPLAY_POINTS);
1454 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1455 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1456 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1457
1458 /* it was not possible to force an error with the fifth parameter on win2k */
1459
1460 /* test combinations of wrong parameters to see which error wins */
1461 SetLastError(MYERROR);
1462 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)-1, NULL, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1463 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1464 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1465 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1466
1467 SetLastError(MYERROR);
1468 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)-1, &in, NULL, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1469 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1470 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1471 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1472
1473 SetLastError(MYERROR);
1474 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), NULL, out, BUFLIM+1, GMMP_USE_DISPLAY_POINTS);
1475 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1476 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1477 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1478
1479 SetLastError(MYERROR);
1480 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, NULL, BUFLIM+1, GMMP_USE_DISPLAY_POINTS);
1481 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1482 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == MYERROR,
1483 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1484
1485 #undef BUFLIM
1486 #undef MYERROR
1487 }
1488
1489 static void test_key_map(void)
1490 {
1491 HKL kl = GetKeyboardLayout(0);
1492 UINT kL, kR, s, sL;
1493 int i;
1494 static const UINT numpad_collisions[][2] = {
1495 { VK_NUMPAD0, VK_INSERT },
1496 { VK_NUMPAD1, VK_END },
1497 { VK_NUMPAD2, VK_DOWN },
1498 { VK_NUMPAD3, VK_NEXT },
1499 { VK_NUMPAD4, VK_LEFT },
1500 { VK_NUMPAD6, VK_RIGHT },
1501 { VK_NUMPAD7, VK_HOME },
1502 { VK_NUMPAD8, VK_UP },
1503 { VK_NUMPAD9, VK_PRIOR },
1504 };
1505
1506 s = MapVirtualKeyExA(VK_SHIFT, MAPVK_VK_TO_VSC, kl);
1507 ok(s != 0, "MapVirtualKeyEx(VK_SHIFT) should return non-zero\n");
1508 sL = MapVirtualKeyExA(VK_LSHIFT, MAPVK_VK_TO_VSC, kl);
1509 ok(s == sL || broken(sL == 0), /* win9x */
1510 "%x != %x\n", s, sL);
1511
1512 kL = MapVirtualKeyExA(0x2a, MAPVK_VSC_TO_VK, kl);
1513 ok(kL == VK_SHIFT, "Scan code -> vKey = %x (not VK_SHIFT)\n", kL);
1514 kR = MapVirtualKeyExA(0x36, MAPVK_VSC_TO_VK, kl);
1515 ok(kR == VK_SHIFT, "Scan code -> vKey = %x (not VK_SHIFT)\n", kR);
1516
1517 kL = MapVirtualKeyExA(0x2a, MAPVK_VSC_TO_VK_EX, kl);
1518 ok(kL == VK_LSHIFT || broken(kL == 0), /* win9x */
1519 "Scan code -> vKey = %x (not VK_LSHIFT)\n", kL);
1520 kR = MapVirtualKeyExA(0x36, MAPVK_VSC_TO_VK_EX, kl);
1521 ok(kR == VK_RSHIFT || broken(kR == 0), /* win9x */
1522 "Scan code -> vKey = %x (not VK_RSHIFT)\n", kR);
1523
1524 /* test that MAPVK_VSC_TO_VK prefers the non-numpad vkey if there's ambiguity */
1525 for (i = 0; i < sizeof(numpad_collisions)/sizeof(numpad_collisions[0]); i++)
1526 {
1527 UINT numpad_scan = MapVirtualKeyExA(numpad_collisions[i][0], MAPVK_VK_TO_VSC, kl);
1528 UINT other_scan = MapVirtualKeyExA(numpad_collisions[i][1], MAPVK_VK_TO_VSC, kl);
1529
1530 /* do they really collide for this layout? */
1531 if (numpad_scan && other_scan == numpad_scan)
1532 {
1533 UINT vkey = MapVirtualKeyExA(numpad_scan, MAPVK_VSC_TO_VK, kl);
1534 ok(vkey != numpad_collisions[i][0],
1535 "Got numpad vKey %x for scan code %x when there was another choice\n",
1536 vkey, numpad_scan);
1537 }
1538 }
1539 }
1540
1541 static void test_ToUnicode(void)
1542 {
1543 WCHAR wStr[4];
1544 BYTE state[256];
1545 const BYTE SC_RETURN = 0x1c, SC_TAB = 0x0f, SC_A = 0x1e;
1546 const BYTE HIGHEST_BIT = 0x80;
1547 int i, ret;
1548 for(i=0; i<256; i++)
1549 state[i]=0;
1550
1551 wStr[1] = 0xAA;
1552 SetLastError(0xdeadbeef);
1553 ret = ToUnicode(VK_RETURN, SC_RETURN, state, wStr, 4, 0);
1554 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1555 {
1556 win_skip("ToUnicode is not implemented\n");
1557 return;
1558 }
1559
1560 ok(ret == 1, "ToUnicode for Return key didn't return 1 (was %i)\n", ret);
1561 if(ret == 1)
1562 {
1563 ok(wStr[0]=='\r', "ToUnicode for CTRL + Return was %i (expected 13)\n", wStr[0]);
1564 ok(wStr[1]==0 || broken(wStr[1]!=0) /* nt4 */,
1565 "ToUnicode didn't null-terminate the buffer when there was room.\n");
1566 }
1567
1568 ret = ToUnicode('A', SC_A, state, wStr, 4, 0);
1569 ok(ret == 1, "ToUnicode for character A didn't return 1 (was %i)\n", ret);
1570 ok(wStr[0] == 'a', "ToUnicode for character 'A' was %i (expected %i)\n", wStr[0], 'a');
1571
1572 state[VK_CONTROL] |= HIGHEST_BIT;
1573 state[VK_LCONTROL] |= HIGHEST_BIT;
1574 ret = ToUnicode(VK_TAB, SC_TAB, state, wStr, 2, 0);
1575 ok(ret == 0, "ToUnicode for CTRL + Tab didn't return 0 (was %i)\n", ret);
1576
1577 ret = ToUnicode(VK_RETURN, SC_RETURN, state, wStr, 2, 0);
1578 ok(ret == 1, "ToUnicode for CTRL + Return didn't return 1 (was %i)\n", ret);
1579 if(ret == 1)
1580 ok(wStr[0]=='\n', "ToUnicode for CTRL + Return was %i (expected 10)\n", wStr[0]);
1581
1582 ret = ToUnicode('A', SC_A, state, wStr, 4, 0);
1583 ok(ret == 1, "ToUnicode for CTRL + character A didn't return 1 (was %i)\n", ret);
1584 ok(wStr[0] == 1, "ToUnicode for CTRL + character 'A' was %i (expected 1)\n", wStr[0]);
1585
1586 state[VK_SHIFT] |= HIGHEST_BIT;
1587 state[VK_LSHIFT] |= HIGHEST_BIT;
1588 ret = ToUnicode(VK_TAB, SC_TAB, state, wStr, 2, 0);
1589 ok(ret == 0, "ToUnicode for CTRL + SHIFT + Tab didn't return 0 (was %i)\n", ret);
1590 ret = ToUnicode(VK_RETURN, SC_RETURN, state, wStr, 2, 0);
1591 todo_wine ok(ret == 0, "ToUnicode for CTRL + SHIFT + Return didn't return 0 (was %i)\n", ret);
1592
1593 ret = ToUnicode(VK_TAB, SC_TAB, NULL, wStr, 4, 0);
1594 ok(ret == 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret);
1595 ret = ToUnicode(VK_RETURN, SC_RETURN, NULL, wStr, 4, 0);
1596 ok(ret == 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret);
1597 ret = ToUnicode('A', SC_A, NULL, wStr, 4, 0);
1598 ok(ret == 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret);
1599 ret = ToUnicodeEx(VK_TAB, SC_TAB, NULL, wStr, 4, 0, GetKeyboardLayout(0));
1600 ok(ret == 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret);
1601 ret = ToUnicodeEx(VK_RETURN, SC_RETURN, NULL, wStr, 4, 0, GetKeyboardLayout(0));
1602 ok(ret == 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret);
1603 ret = ToUnicodeEx('A', SC_A, NULL, wStr, 4, 0, GetKeyboardLayout(0));
1604 ok(ret == 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret);
1605 }
1606
1607 static void test_ToAscii(void)
1608 {
1609 WORD character;
1610 BYTE state[256];
1611 const BYTE SC_RETURN = 0x1c, SC_A = 0x1e;
1612 const BYTE HIGHEST_BIT = 0x80;
1613 int ret;
1614
1615 memset(state, 0, sizeof(state));
1616
1617 character = 0;
1618 ret = ToAscii(VK_RETURN, SC_RETURN, state, &character, 0);
1619 ok(ret == 1, "ToAscii for Return key didn't return 1 (was %i)\n", ret);
1620 ok(character == '\r', "ToAscii for Return was %i (expected 13)\n", character);
1621
1622 character = 0;
1623 ret = ToAscii('A', SC_A, state, &character, 0);
1624 ok(ret == 1, "ToAscii for character 'A' didn't return 1 (was %i)\n", ret);
1625 ok(character == 'a', "ToAscii for character 'A' was %i (expected %i)\n", character, 'a');
1626
1627 state[VK_CONTROL] |= HIGHEST_BIT;
1628 state[VK_LCONTROL] |= HIGHEST_BIT;
1629 character = 0;
1630 ret = ToAscii(VK_RETURN, SC_RETURN, state, &character, 0);
1631 ok(ret == 1, "ToAscii for CTRL + Return key didn't return 1 (was %i)\n", ret);
1632 ok(character == '\n', "ToAscii for CTRL + Return was %i (expected 10)\n", character);
1633
1634 character = 0;
1635 ret = ToAscii('A', SC_A, state, &character, 0);
1636 ok(ret == 1, "ToAscii for CTRL + character 'A' didn't return 1 (was %i)\n", ret);
1637 ok(character == 1, "ToAscii for CTRL + character 'A' was %i (expected 1)\n", character);
1638
1639 state[VK_SHIFT] |= HIGHEST_BIT;
1640 state[VK_LSHIFT] |= HIGHEST_BIT;
1641 ret = ToAscii(VK_RETURN, SC_RETURN, state, &character, 0);
1642 todo_wine ok(ret == 0, "ToAscii for CTRL + Shift + Return key didn't return 0 (was %i)\n", ret);
1643
1644 ret = ToAscii(VK_RETURN, SC_RETURN, NULL, &character, 0);
1645 ok(ret == 0, "ToAscii for NULL keystate didn't return 0 (was %i)\n", ret);
1646 ret = ToAscii('A', SC_A, NULL, &character, 0);
1647 ok(ret == 0, "ToAscii for NULL keystate didn't return 0 (was %i)\n", ret);
1648 ret = ToAsciiEx(VK_RETURN, SC_RETURN, NULL, &character, 0, GetKeyboardLayout(0));
1649 ok(ret == 0, "ToAsciiEx for NULL keystate didn't return 0 (was %i)\n", ret);
1650 ret = ToAsciiEx('A', SC_A, NULL, &character, 0, GetKeyboardLayout(0));
1651 ok(ret == 0, "ToAsciiEx for NULL keystate didn't return 0 (was %i)\n", ret);
1652 }
1653
1654 static void test_get_async_key_state(void)
1655 {
1656 /* input value sanity checks */
1657 ok(0 == GetAsyncKeyState(1000000), "GetAsyncKeyState did not return 0\n");
1658 ok(0 == GetAsyncKeyState(-1000000), "GetAsyncKeyState did not return 0\n");
1659 }
1660
1661 static void test_keyboard_layout_name(void)
1662 {
1663 BOOL ret;
1664 char klid[KL_NAMELENGTH];
1665
1666 if (0) /* crashes on native system */
1667 ret = GetKeyboardLayoutNameA(NULL);
1668
1669 SetLastError(0xdeadbeef);
1670 ret = GetKeyboardLayoutNameW(NULL);
1671 ok(!ret, "got %d\n", ret);
1672 ok(GetLastError() == ERROR_NOACCESS, "got %d\n", GetLastError());
1673
1674 if (GetKeyboardLayout(0) != (HKL)(ULONG_PTR)0x04090409) return;
1675
1676 klid[0] = 0;
1677 ret = GetKeyboardLayoutNameA(klid);
1678 ok(ret, "GetKeyboardLayoutNameA failed %u\n", GetLastError());
1679 ok(!strcmp(klid, "00000409"), "expected 00000409, got %s\n", klid);
1680 }
1681
1682 static void test_key_names(void)
1683 {
1684 char buffer[40];
1685 WCHAR bufferW[40];
1686 int ret, prev;
1687 LONG lparam = 0x1d << 16;
1688
1689 memset( buffer, 0xcc, sizeof(buffer) );
1690 ret = GetKeyNameTextA( lparam, buffer, sizeof(buffer) );
1691 ok( ret > 0, "wrong len %u for '%s'\n", ret, buffer );
1692 ok( ret == strlen(buffer), "wrong len %u for '%s'\n", ret, buffer );
1693
1694 memset( buffer, 0xcc, sizeof(buffer) );
1695 prev = ret;
1696 ret = GetKeyNameTextA( lparam, buffer, prev );
1697 ok( ret == prev - 1, "wrong len %u for '%s'\n", ret, buffer );
1698 ok( ret == strlen(buffer), "wrong len %u for '%s'\n", ret, buffer );
1699
1700 memset( buffer, 0xcc, sizeof(buffer) );
1701 ret = GetKeyNameTextA( lparam, buffer, 0 );
1702 ok( ret == 0, "wrong len %u for '%s'\n", ret, buffer );
1703 ok( buffer[0] == 0, "wrong string '%s'\n", buffer );
1704
1705 memset( bufferW, 0xcc, sizeof(bufferW) );
1706 ret = GetKeyNameTextW( lparam, bufferW, sizeof(bufferW)/sizeof(WCHAR) );
1707 ok( ret > 0, "wrong len %u for %s\n", ret, wine_dbgstr_w(bufferW) );
1708 ok( ret == lstrlenW(bufferW), "wrong len %u for %s\n", ret, wine_dbgstr_w(bufferW) );
1709
1710 memset( bufferW, 0xcc, sizeof(bufferW) );
1711 prev = ret;
1712 ret = GetKeyNameTextW( lparam, bufferW, prev );
1713 ok( ret == prev - 1, "wrong len %u for %s\n", ret, wine_dbgstr_w(bufferW) );
1714 ok( ret == lstrlenW(bufferW), "wrong len %u for %s\n", ret, wine_dbgstr_w(bufferW) );
1715
1716 memset( bufferW, 0xcc, sizeof(bufferW) );
1717 ret = GetKeyNameTextW( lparam, bufferW, 0 );
1718 ok( ret == 0, "wrong len %u for %s\n", ret, wine_dbgstr_w(bufferW) );
1719 ok( bufferW[0] == 0xcccc, "wrong string %s\n", wine_dbgstr_w(bufferW) );
1720 }
1721
1722 static void simulate_click(BOOL left, int x, int y)
1723 {
1724 INPUT input[2];
1725 UINT events_no;
1726
1727 SetCursorPos(x, y);
1728 memset(input, 0, sizeof(input));
1729 input[0].type = INPUT_MOUSE;
1730 U(input[0]).mi.dx = x;
1731 U(input[0]).mi.dy = y;
1732 U(input[0]).mi.dwFlags = left ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN;
1733 input[1].type = INPUT_MOUSE;
1734 U(input[1]).mi.dx = x;
1735 U(input[1]).mi.dy = y;
1736 U(input[1]).mi.dwFlags = left ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP;
1737 events_no = SendInput(2, input, sizeof(input[0]));
1738 ok(events_no == 2, "SendInput returned %d\n", events_no);
1739 }
1740
1741 static BOOL wait_for_message( MSG *msg )
1742 {
1743 BOOL ret;
1744
1745 for (;;)
1746 {
1747 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
1748 if (ret)
1749 {
1750 if (msg->message == WM_PAINT) DispatchMessageA(msg);
1751 else break;
1752 }
1753 else if (MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT) == WAIT_TIMEOUT) break;
1754 }
1755 if (!ret) msg->message = 0;
1756 return ret;
1757 }
1758
1759 static BOOL wait_for_event(HANDLE event, int timeout)
1760 {
1761 DWORD end_time = GetTickCount() + timeout;
1762 MSG msg;
1763
1764 do {
1765 if(MsgWaitForMultipleObjects(1, &event, FALSE, timeout, QS_ALLINPUT) == WAIT_OBJECT_0)
1766 return TRUE;
1767 while(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
1768 DispatchMessageA(&msg);
1769 timeout = end_time - GetTickCount();
1770 }while(timeout > 0);
1771
1772 return FALSE;
1773 }
1774
1775 static WNDPROC def_static_proc;
1776 static DWORD hittest_no;
1777 static LRESULT WINAPI static_hook_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1778 {
1779 if (msg == WM_NCHITTEST)
1780 {
1781 /* break infinite hittest loop */
1782 if(hittest_no > 50) return HTCLIENT;
1783 hittest_no++;
1784 }
1785
1786 return def_static_proc(hwnd, msg, wp, lp);
1787 }
1788
1789 struct thread_data
1790 {
1791 HANDLE start_event;
1792 HANDLE end_event;
1793 HWND win;
1794 };
1795
1796 static DWORD WINAPI create_static_win(void *arg)
1797 {
1798 struct thread_data *thread_data = arg;
1799 HWND win;
1800
1801 win = CreateWindowA("static", "static", WS_VISIBLE | WS_POPUP,
1802 100, 100, 100, 100, 0, NULL, NULL, NULL);
1803 ok(win != 0, "CreateWindow failed\n");
1804 def_static_proc = (void*)SetWindowLongPtrA(win,
1805 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
1806 thread_data->win = win;
1807
1808 SetEvent(thread_data->start_event);
1809 wait_for_event(thread_data->end_event, 5000);
1810 return 0;
1811 }
1812
1813 static void test_Input_mouse(void)
1814 {
1815 BOOL got_button_down, got_button_up;
1816 HWND hwnd, button_win, static_win;
1817 struct thread_data thread_data;
1818 HANDLE thread;
1819 DWORD thread_id;
1820 POINT pt;
1821 MSG msg;
1822
1823 button_win = CreateWindowA("button", "button", WS_VISIBLE | WS_POPUP,
1824 100, 100, 100, 100, 0, NULL, NULL, NULL);
1825 ok(button_win != 0, "CreateWindow failed\n");
1826
1827 pt.x = pt.y = 150;
1828 hwnd = WindowFromPoint(pt);
1829 if (hwnd != button_win)
1830 {
1831 skip("there's another window covering test window\n");
1832 DestroyWindow(button_win);
1833 return;
1834 }
1835
1836 /* simple button click test */
1837 simulate_click(TRUE, 150, 150);
1838 got_button_down = got_button_up = FALSE;
1839 while (wait_for_message(&msg))
1840 {
1841 DispatchMessageA(&msg);
1842
1843 if (msg.message == WM_LBUTTONDOWN)
1844 {
1845 got_button_down = TRUE;
1846 }
1847 else if (msg.message == WM_LBUTTONUP)
1848 {
1849 got_button_up = TRUE;
1850 break;
1851 }
1852 }
1853 ok(got_button_down, "expected WM_LBUTTONDOWN message\n");
1854 ok(got_button_up, "expected WM_LBUTTONUP message\n");
1855
1856 /* click through HTTRANSPARENT child window */
1857 static_win = CreateWindowA("static", "static", WS_VISIBLE | WS_CHILD,
1858 0, 0, 100, 100, button_win, NULL, NULL, NULL);
1859 ok(static_win != 0, "CreateWindow failed\n");
1860 def_static_proc = (void*)SetWindowLongPtrA(static_win,
1861 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
1862 simulate_click(FALSE, 150, 150);
1863 hittest_no = 0;
1864 got_button_down = got_button_up = FALSE;
1865 while (wait_for_message(&msg))
1866 {
1867 DispatchMessageA(&msg);
1868
1869 if (msg.message == WM_RBUTTONDOWN)
1870 {
1871 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
1872 got_button_down = TRUE;
1873 }
1874 else if (msg.message == WM_RBUTTONUP)
1875 {
1876 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
1877 got_button_up = TRUE;
1878 break;
1879 }
1880 }
1881 ok(hittest_no && hittest_no<50, "expected WM_NCHITTEST message\n");
1882 ok(got_button_down, "expected WM_RBUTTONDOWN message\n");
1883 ok(got_button_up, "expected WM_RBUTTONUP message\n");
1884 DestroyWindow(static_win);
1885
1886 /* click through HTTRANSPARENT top-level window */
1887 static_win = CreateWindowA("static", "static", WS_VISIBLE | WS_POPUP,
1888 100, 100, 100, 100, 0, NULL, NULL, NULL);
1889 ok(static_win != 0, "CreateWindow failed\n");
1890 def_static_proc = (void*)SetWindowLongPtrA(static_win,
1891 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
1892 simulate_click(TRUE, 150, 150);
1893 hittest_no = 0;
1894 got_button_down = got_button_up = FALSE;
1895 while (wait_for_message(&msg))
1896 {
1897 DispatchMessageA(&msg);
1898
1899 if (msg.message == WM_LBUTTONDOWN)
1900 {
1901 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
1902 got_button_down = TRUE;
1903 }
1904 else if (msg.message == WM_LBUTTONUP)
1905 {
1906 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
1907 got_button_up = TRUE;
1908 break;
1909 }
1910 }
1911 ok(hittest_no && hittest_no<50, "expected WM_NCHITTEST message\n");
1912 ok(got_button_down, "expected WM_LBUTTONDOWN message\n");
1913 ok(got_button_up, "expected WM_LBUTTONUP message\n");
1914 DestroyWindow(static_win);
1915
1916 /* click on HTTRANSPARENT top-level window that belongs to other thread */
1917 thread_data.start_event = CreateEventA(NULL, FALSE, FALSE, NULL);
1918 ok(thread_data.start_event != NULL, "CreateEvent failed\n");
1919 thread_data.end_event = CreateEventA(NULL, FALSE, FALSE, NULL);
1920 ok(thread_data.end_event != NULL, "CreateEvent failed\n");
1921 thread = CreateThread(NULL, 0, create_static_win, &thread_data, 0, NULL);
1922 ok(thread != NULL, "CreateThread failed\n");
1923 hittest_no = 0;
1924 got_button_down = got_button_up = FALSE;
1925 WaitForSingleObject(thread_data.start_event, INFINITE);
1926 simulate_click(FALSE, 150, 150);
1927 while (wait_for_message(&msg))
1928 {
1929 DispatchMessageA(&msg);
1930
1931 if (msg.message == WM_RBUTTONDOWN)
1932 got_button_down = TRUE;
1933 else if (msg.message == WM_RBUTTONUP)
1934 got_button_up = TRUE;
1935 }
1936 SetEvent(thread_data.end_event);
1937 WaitForSingleObject(thread, INFINITE);
1938 ok(hittest_no && hittest_no<50, "expected WM_NCHITTEST message\n");
1939 ok(!got_button_down, "unexpected WM_RBUTTONDOWN message\n");
1940 ok(!got_button_up, "unexpected WM_RBUTTONUP message\n");
1941
1942 /* click on HTTRANSPARENT top-level window that belongs to other thread,
1943 * thread input queues are attached */
1944 thread = CreateThread(NULL, 0, create_static_win, &thread_data, 0, &thread_id);
1945 ok(thread != NULL, "CreateThread failed\n");
1946 hittest_no = 0;
1947 got_button_down = got_button_up = FALSE;
1948 WaitForSingleObject(thread_data.start_event, INFINITE);
1949 ok(AttachThreadInput(thread_id, GetCurrentThreadId(), TRUE),
1950 "AttachThreadInput failed\n");
1951 while (wait_for_message(&msg)) DispatchMessageA(&msg);
1952 SetWindowPos(thread_data.win, button_win, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1953 simulate_click(TRUE, 150, 150);
1954 while (wait_for_message(&msg))
1955 {
1956 DispatchMessageA(&msg);
1957
1958 if (msg.message == WM_LBUTTONDOWN)
1959 got_button_down = TRUE;
1960 else if (msg.message == WM_LBUTTONUP)
1961 got_button_up = TRUE;
1962 }
1963 SetEvent(thread_data.end_event);
1964 WaitForSingleObject(thread, INFINITE);
1965 todo_wine ok(hittest_no > 50, "expected loop with WM_NCHITTEST messages\n");
1966 ok(!got_button_down, "unexpected WM_LBUTTONDOWN message\n");
1967 ok(!got_button_up, "unexpected WM_LBUTTONUP message\n");
1968
1969 /* click after SetCapture call */
1970 hwnd = CreateWindowA("button", "button", WS_VISIBLE | WS_POPUP,
1971 0, 0, 100, 100, 0, NULL, NULL, NULL);
1972 ok(hwnd != 0, "CreateWindow failed\n");
1973 SetCapture(button_win);
1974 got_button_down = got_button_up = FALSE;
1975 simulate_click(FALSE, 50, 50);
1976 while (wait_for_message(&msg))
1977 {
1978 DispatchMessageA(&msg);
1979
1980 if (msg.message == WM_RBUTTONDOWN)
1981 {
1982 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
1983 got_button_down = TRUE;
1984 }
1985 else if (msg.message == WM_RBUTTONUP)
1986 {
1987 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
1988 got_button_up = TRUE;
1989 break;
1990 }
1991 }
1992 ok(got_button_down, "expected WM_RBUTTONDOWN message\n");
1993 ok(got_button_up, "expected WM_RBUTTONUP message\n");
1994 DestroyWindow(hwnd);
1995
1996 /* click on child window after SetCapture call */
1997 hwnd = CreateWindowA("button", "button2", WS_VISIBLE | WS_CHILD,
1998 0, 0, 100, 100, button_win, NULL, NULL, NULL);
1999 ok(hwnd != 0, "CreateWindow failed\n");
2000 got_button_down = got_button_up = FALSE;
2001 simulate_click(TRUE, 150, 150);
2002 while (wait_for_message(&msg))
2003 {
2004 DispatchMessageA(&msg);
2005
2006 if (msg.message == WM_LBUTTONDOWN)
2007 {
2008 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
2009 got_button_down = TRUE;
2010 }
2011 else if (msg.message == WM_LBUTTONUP)
2012 {
2013 ok(msg.hwnd == button_win, "msg.hwnd = %p\n", msg.hwnd);
2014 got_button_up = TRUE;
2015 break;
2016 }
2017 }
2018 ok(got_button_down, "expected WM_LBUTTONDOWN message\n");
2019 ok(got_button_up, "expected WM_LBUTTONUP message\n");
2020 DestroyWindow(hwnd);
2021 ok(ReleaseCapture(), "ReleaseCapture failed\n");
2022
2023 CloseHandle(thread_data.start_event);
2024 CloseHandle(thread_data.end_event);
2025 DestroyWindow(button_win);
2026 }
2027
2028
2029 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2030 {
2031 if (message == WM_USER+1)
2032 {
2033 HWND hwnd = (HWND)lParam;
2034 ok(GetFocus() == hwnd, "thread expected focus %p, got %p\n", hwnd, GetFocus());
2035 ok(GetActiveWindow() == hwnd, "thread expected active %p, got %p\n", hwnd, GetActiveWindow());
2036 }
2037 return DefWindowProcA(hwnd, message, wParam, lParam);
2038 }
2039
2040 struct wnd_event
2041 {
2042 HWND hwnd;
2043 HANDLE wait_event;
2044 HANDLE start_event;
2045 DWORD attach_from;
2046 DWORD attach_to;
2047 BOOL setWindows;
2048 };
2049
2050 static DWORD WINAPI thread_proc(void *param)
2051 {
2052 MSG msg;
2053 struct wnd_event *wnd_event = param;
2054 BOOL ret;
2055
2056 if (wnd_event->wait_event)
2057 {
2058 ok(WaitForSingleObject(wnd_event->wait_event, INFINITE) == WAIT_OBJECT_0,
2059 "WaitForSingleObject failed\n");
2060 CloseHandle(wnd_event->wait_event);
2061 }
2062
2063 if (wnd_event->attach_from)
2064 {
2065 ret = AttachThreadInput(wnd_event->attach_from, GetCurrentThreadId(), TRUE);
2066 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2067 }
2068
2069 if (wnd_event->attach_to)
2070 {
2071 ret = AttachThreadInput(GetCurrentThreadId(), wnd_event->attach_to, TRUE);
2072 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2073 }
2074
2075 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
2076 100, 100, 200, 200, 0, 0, 0, NULL);
2077 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
2078
2079 if (wnd_event->setWindows)
2080 {
2081 SetFocus(wnd_event->hwnd);
2082 SetActiveWindow(wnd_event->hwnd);
2083 }
2084
2085 SetEvent(wnd_event->start_event);
2086
2087 while (GetMessageA(&msg, 0, 0, 0))
2088 {
2089 TranslateMessage(&msg);
2090 DispatchMessageA(&msg);
2091 }
2092
2093 return 0;
2094 }
2095
2096 static void test_attach_input(void)
2097 {
2098 HANDLE hThread;
2099 HWND ourWnd, Wnd2;
2100 DWORD ret, tid;
2101 struct wnd_event wnd_event;
2102 WNDCLASSA cls;
2103
2104 cls.style = 0;
2105 cls.lpfnWndProc = MsgCheckProcA;
2106 cls.cbClsExtra = 0;
2107 cls.cbWndExtra = 0;
2108 cls.hInstance = GetModuleHandleA(0);
2109 cls.hIcon = 0;
2110 cls.hCursor = LoadCursorW( NULL, (LPCWSTR)IDC_ARROW);
2111 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2112 cls.lpszMenuName = NULL;
2113 cls.lpszClassName = "TestWindowClass";
2114 if(!RegisterClassA(&cls)) return;
2115
2116 wnd_event.wait_event = NULL;
2117 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
2118 wnd_event.attach_from = 0;
2119 wnd_event.attach_to = 0;
2120 wnd_event.setWindows = FALSE;
2121 if (!wnd_event.start_event)
2122 {
2123 win_skip("skipping interthread message test under win9x\n");
2124 return;
2125 }
2126
2127 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
2128 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
2129
2130 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2131 CloseHandle(wnd_event.start_event);
2132
2133 ourWnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
2134 0, 0, 0, 0, 0, 0, 0, NULL);
2135 ok(ourWnd!= 0, "failed to create ourWnd window\n");
2136
2137 Wnd2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
2138 0, 0, 0, 0, 0, 0, 0, NULL);
2139 ok(Wnd2!= 0, "failed to create Wnd2 window\n");
2140
2141 SetFocus(ourWnd);
2142 SetActiveWindow(ourWnd);
2143
2144 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
2145 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2146
2147 ok(GetActiveWindow() == ourWnd, "expected active %p, got %p\n", ourWnd, GetActiveWindow());
2148 ok(GetFocus() == ourWnd, "expected focus %p, got %p\n", ourWnd, GetFocus());
2149
2150 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)ourWnd);
2151
2152 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
2153 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2154 ok(GetActiveWindow() == ourWnd, "expected active %p, got %p\n", ourWnd, GetActiveWindow());
2155 ok(GetFocus() == ourWnd, "expected focus %p, got %p\n", ourWnd, GetFocus());
2156
2157 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, 0);
2158
2159 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
2160 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2161
2162 ok(GetActiveWindow() == ourWnd, "expected active %p, got %p\n", ourWnd, GetActiveWindow());
2163 ok(GetFocus() == ourWnd, "expected focus %p, got %p\n", ourWnd, GetFocus());
2164 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)ourWnd);
2165
2166 SetActiveWindow(Wnd2);
2167 SetFocus(Wnd2);
2168 ok(GetActiveWindow() == Wnd2, "expected active %p, got %p\n", Wnd2, GetActiveWindow());
2169 ok(GetFocus() == Wnd2, "expected focus %p, got %p\n", Wnd2, GetFocus());
2170
2171 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)Wnd2);
2172
2173 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
2174 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2175 ok(GetActiveWindow() == Wnd2, "expected active %p, got %p\n", Wnd2, GetActiveWindow());
2176 ok(GetFocus() == Wnd2, "expected focus %p, got %p\n", Wnd2, GetFocus());
2177
2178 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, 0);
2179
2180 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
2181 ok(ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2182
2183 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2184 CloseHandle(hThread);
2185
2186 wnd_event.wait_event = NULL;
2187 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
2188 wnd_event.attach_from = 0;
2189 wnd_event.attach_to = 0;
2190 wnd_event.setWindows = TRUE;
2191
2192 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
2193 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
2194
2195 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2196 CloseHandle(wnd_event.start_event);
2197
2198 SetFocus(ourWnd);
2199 SetActiveWindow(ourWnd);
2200
2201 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
2202 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2203
2204 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
2205 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
2206
2207 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)wnd_event.hwnd);
2208
2209 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
2210 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2211
2212 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
2213 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
2214
2215 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)wnd_event.hwnd);
2216
2217 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
2218 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2219
2220 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
2221 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
2222
2223 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)wnd_event.hwnd);
2224
2225 SetFocus(Wnd2);
2226 SetActiveWindow(Wnd2);
2227 ok(GetActiveWindow() == Wnd2, "expected active %p, got %p\n", Wnd2, GetActiveWindow());
2228 ok(GetFocus() == Wnd2, "expected focus %p, got %p\n", Wnd2, GetFocus());
2229
2230 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, (LPARAM)Wnd2);
2231
2232 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
2233 ok(ret, "AttachThreadInput error %d\n", GetLastError());
2234
2235 ok(GetActiveWindow() == Wnd2, "expected active %p, got %p\n", Wnd2, GetActiveWindow());
2236 ok(GetFocus() == Wnd2, "expected focus %p, got %p\n", Wnd2, GetFocus());
2237
2238 SendMessageA(wnd_event.hwnd, WM_USER+1, 0, 0);
2239
2240 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
2241 ok(ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2242
2243 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2244 CloseHandle(hThread);
2245
2246 wnd_event.wait_event = CreateEventW(NULL, 0, 0, NULL);
2247 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
2248 wnd_event.attach_from = 0;
2249 wnd_event.attach_to = 0;
2250 wnd_event.setWindows = TRUE;
2251
2252 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
2253 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
2254
2255 SetLastError(0xdeadbeef);
2256 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
2257 ok(!ret, "AttachThreadInput succeeded\n");
2258 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef) /* <= Win XP */,
2259 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2260
2261 SetLastError(0xdeadbeef);
2262 ret = AttachThreadInput(tid, GetCurrentThreadId(), TRUE);
2263 ok(!ret, "AttachThreadInput succeeded\n");
2264 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef) /* <= Win XP */,
2265 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2266
2267 SetEvent(wnd_event.wait_event);
2268
2269 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2270 CloseHandle(wnd_event.start_event);
2271
2272 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
2273 ok(ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2274
2275 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2276 CloseHandle(hThread);
2277
2278 wnd_event.wait_event = NULL;
2279 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
2280 wnd_event.attach_from = GetCurrentThreadId();
2281 wnd_event.attach_to = 0;
2282 wnd_event.setWindows = FALSE;
2283
2284 SetFocus(ourWnd);
2285 SetActiveWindow(ourWnd);
2286
2287 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
2288 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
2289
2290 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2291 CloseHandle(wnd_event.start_event);
2292
2293 ok(GetActiveWindow() == ourWnd, "expected active %p, got %p\n", ourWnd, GetActiveWindow());
2294 ok(GetFocus() == ourWnd, "expected focus %p, got %p\n", ourWnd, GetFocus());
2295
2296 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
2297 ok(ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2298
2299 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2300 CloseHandle(hThread);
2301
2302 wnd_event.wait_event = NULL;
2303 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
2304 wnd_event.attach_from = 0;
2305 wnd_event.attach_to = GetCurrentThreadId();
2306 wnd_event.setWindows = FALSE;
2307
2308 SetFocus(ourWnd);
2309 SetActiveWindow(ourWnd);
2310
2311 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
2312 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
2313
2314 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2315 CloseHandle(wnd_event.start_event);
2316
2317 ok(GetActiveWindow() == ourWnd, "expected active %p, got %p\n", ourWnd, GetActiveWindow());
2318 ok(GetFocus() == ourWnd, "expected focus %p, got %p\n", ourWnd, GetFocus());
2319
2320 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
2321 ok(ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2322
2323 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
2324 CloseHandle(hThread);
2325 DestroyWindow(ourWnd);
2326 DestroyWindow(Wnd2);
2327 }
2328
2329 START_TEST(input)
2330 {
2331 init_function_pointers();
2332
2333 if (pSendInput)
2334 {
2335 test_Input_blackbox();
2336 test_Input_whitebox();
2337 test_Input_unicode();
2338 test_Input_mouse();
2339 }
2340 else win_skip("SendInput is not available\n");
2341
2342 test_keynames();
2343 test_mouse_ll_hook();
2344 test_key_map();
2345 test_ToUnicode();
2346 test_ToAscii();
2347 test_get_async_key_state();
2348 test_keyboard_layout_name();
2349 test_key_names();
2350 test_attach_input();
2351
2352 if(pGetMouseMovePointsEx)
2353 test_GetMouseMovePointsEx();
2354 else
2355 win_skip("GetMouseMovePointsEx is not available\n");
2356 }