winex11: Fix MapVirtualKeyEx to properly map left-right modifier keys.
[wine/gsoc_dplay.git] / dlls / user32 / tests / input.c
blobdd597d83205eca492f3ef9d480c76379f51824d5
1 /* Test Key event to Key message translation
3 * Copyright 2003 Rein Klazes
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.
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.
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
20 /* test whether the right type of messages:
21 * WM_KEYUP/DOWN vs WM_SYSKEYUP/DOWN are sent in case of combined
22 * keystrokes.
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 */
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 */
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.
47 #define _WIN32_WINNT 0x401
49 #include <stdarg.h>
50 #include <assert.h>
52 #include "windef.h"
53 #include "winbase.h"
54 #include "winuser.h"
56 #include "wine/test.h"
58 /* globals */
59 static HWND hWndTest;
60 static long timetag = 0x10000000;
62 static UINT (WINAPI *pSendInput) (UINT, INPUT*, size_t);
63 static int (WINAPI *pGetMouseMovePointsEx) (UINT, LPMOUSEMOVEPOINT, LPMOUSEMOVEPOINT, int, DWORD);
65 #define MAXKEYEVENTS 6
66 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
67 and only one message */
69 /* keyboard message names, sorted as their value */
70 static const char *MSGNAME[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
71 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
73 /* keyevents, add more as needed */
74 typedef enum KEVtag
75 { ALTDOWN = 1, ALTUP, XDOWN, XUP, SHIFTDOWN, SHIFTUP, CTRLDOWN, CTRLUP } KEV;
76 /* matching VK's */
77 static const int GETVKEY[]={0, VK_MENU, VK_MENU, 'X', 'X', VK_SHIFT, VK_SHIFT, VK_CONTROL, VK_CONTROL};
78 /* matching scan codes */
79 static const int GETSCAN[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
80 /* matching updown events */
81 static const int GETFLAGS[]={0, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP, 0, KEYEVENTF_KEYUP};
82 /* matching descriptions */
83 static const char *getdesc[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
85 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
86 typedef struct
88 DWORD type;
89 union
91 MOUSEINPUT mi;
92 KEYBDINPUT ki;
93 HARDWAREINPUT hi;
94 } u;
95 } TEST_INPUT;
97 #define ADDTOINPUTS(kev) \
98 inputs[evtctr].type = INPUT_KEYBOARD; \
99 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
100 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
101 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETFLAGS[ kev]; \
102 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
103 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
104 if( kev) evtctr++;
106 typedef struct {
107 UINT message;
108 WPARAM wParam;
109 LPARAM lParam;
110 } KMSG;
112 /*******************************************
113 * add new test sets here
114 * the software will make all combinations of the
115 * keyevent defined here
117 static const struct {
118 int nrkev;
119 KEV keydwn[MAXKEYEVENTS];
120 KEV keyup[MAXKEYEVENTS];
121 } testkeyset[]= {
122 { 2, { ALTDOWN, XDOWN }, { ALTUP, XUP}},
123 { 3, { ALTDOWN, XDOWN , SHIFTDOWN}, { ALTUP, XUP, SHIFTUP}},
124 { 3, { ALTDOWN, XDOWN , CTRLDOWN}, { ALTUP, XUP, CTRLUP}},
125 { 3, { SHIFTDOWN, XDOWN , CTRLDOWN}, { SHIFTUP, XUP, CTRLUP}},
126 { 0 } /* mark the end */
129 /**********************adapted from input.c **********************************/
131 static BYTE InputKeyStateTable[256];
132 static BYTE AsyncKeyStateTable[256];
133 static BYTE TrackSysKey = 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
134 or a WM_KEYUP message */
136 static void init_function_pointers(void)
138 HMODULE hdll = GetModuleHandleA("user32");
140 #define GET_PROC(func) \
141 p ## func = (void*)GetProcAddress(hdll, #func); \
142 if(!p ## func) \
143 trace("GetProcAddress(%s) failed\n", #func);
145 GET_PROC(SendInput)
146 GET_PROC(GetMouseMovePointsEx)
148 #undef GET_PROC
151 static int KbdMessage( KEV kev, WPARAM *pwParam, LPARAM *plParam )
153 UINT message;
154 int VKey = GETVKEY[kev];
155 WORD flags;
157 flags = LOBYTE(GETSCAN[kev]);
158 if (GETFLAGS[kev] & KEYEVENTF_EXTENDEDKEY) flags |= KF_EXTENDED;
160 if (GETFLAGS[kev] & KEYEVENTF_KEYUP )
162 message = WM_KEYUP;
163 if( (InputKeyStateTable[VK_MENU] & 0x80) && (
164 (VKey == VK_MENU) || (VKey == VK_CONTROL) ||
165 !(InputKeyStateTable[VK_CONTROL] & 0x80))) {
166 if( TrackSysKey == VK_MENU || /* <ALT>-down/<ALT>-up sequence */
167 (VKey != VK_MENU)) /* <ALT>-down...<something else>-up */
168 message = WM_SYSKEYUP;
169 TrackSysKey = 0;
171 InputKeyStateTable[VKey] &= ~0x80;
172 flags |= KF_REPEAT | KF_UP;
174 else
176 if (InputKeyStateTable[VKey] & 0x80) flags |= KF_REPEAT;
177 if (!(InputKeyStateTable[VKey] & 0x80)) InputKeyStateTable[VKey] ^= 0x01;
178 InputKeyStateTable[VKey] |= 0x80;
179 AsyncKeyStateTable[VKey] |= 0x80;
181 message = WM_KEYDOWN;
182 if( (InputKeyStateTable[VK_MENU] & 0x80) &&
183 !(InputKeyStateTable[VK_CONTROL] & 0x80)) {
184 message = WM_SYSKEYDOWN;
185 TrackSysKey = VKey;
189 if (InputKeyStateTable[VK_MENU] & 0x80) flags |= KF_ALTDOWN;
191 if( plParam) *plParam = MAKELPARAM( 1, flags );
192 if( pwParam) *pwParam = VKey;
193 return message;
196 /****************************** end copy input.c ****************************/
199 * . prepare the keyevents for SendInputs
200 * . calculate the "expected" messages
201 * . Send the events to our window
202 * . retrieve the messages from the input queue
203 * . verify
205 static void do_test( HWND hwnd, int seqnr, const KEV td[] )
207 INPUT inputs[MAXKEYEVENTS];
208 KMSG expmsg[MAXKEYEVENTS];
209 MSG msg;
210 char buf[100];
211 UINT evtctr=0;
212 int kmctr, i;
214 buf[0]='\0';
215 TrackSysKey=0; /* see input.c */
216 for( i = 0; i < MAXKEYEVENTS; i++) {
217 ADDTOINPUTS(td[i])
218 strcat(buf, getdesc[td[i]]);
219 if(td[i])
220 expmsg[i].message = KbdMessage(td[i], &(expmsg[i].wParam), &(expmsg[i].lParam)); /* see queue_kbd_event() */
221 else
222 expmsg[i].message = 0;
224 for( kmctr = 0; kmctr < MAXKEYEVENTS && expmsg[kmctr].message; kmctr++)
226 assert( evtctr <= MAXKEYEVENTS );
227 assert( evtctr == pSendInput(evtctr, &inputs[0], sizeof(INPUT)));
228 i = 0;
229 if (winetest_debug > 1)
230 trace("======== key stroke sequence #%d: %s =============\n",
231 seqnr + 1, buf);
232 while( PeekMessage(&msg,hwnd,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE) ) {
233 if (winetest_debug > 1)
234 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i,
235 MSGNAME[msg.message - WM_KEYFIRST], msg.wParam, msg.lParam, msg.time);
236 if( i < kmctr ) {
237 ok( msg.message == expmsg[i].message &&
238 msg.wParam == expmsg[i].wParam &&
239 msg.lParam == expmsg[i].lParam,
240 "wrong message! expected:\n"
241 "message[%d] %-15s wParam %04lx lParam %08lx\n",i,
242 MSGNAME[(expmsg[i]).message - WM_KEYFIRST],
243 expmsg[i].wParam, expmsg[i].lParam );
245 i++;
247 if (winetest_debug > 1)
248 trace("%d messages retrieved\n", i);
249 ok( i == kmctr, "message count is wrong: got %d expected: %d\n", i, kmctr);
252 /* test all combinations of the specified key events */
253 static void TestASet( HWND hWnd, int nrkev, const KEV kevdwn[], const KEV kevup[] )
255 int i,j,k,l,m,n;
256 static int count=0;
257 KEV kbuf[MAXKEYEVENTS];
258 assert( nrkev==2 || nrkev==3);
259 for(i=0;i<MAXKEYEVENTS;i++) kbuf[i]=0;
260 /* two keys involved gives 4 test cases */
261 if(nrkev==2) {
262 for(i=0;i<nrkev;i++) {
263 for(j=0;j<nrkev;j++) {
264 kbuf[0] = kevdwn[i];
265 kbuf[1] = kevdwn[1-i];
266 kbuf[2] = kevup[j];
267 kbuf[3] = kevup[1-j];
268 do_test( hWnd, count++, kbuf);
272 /* three keys involved gives 36 test cases */
273 if(nrkev==3){
274 for(i=0;i<nrkev;i++){
275 for(j=0;j<nrkev;j++){
276 if(j==i) continue;
277 for(k=0;k<nrkev;k++){
278 if(k==i || k==j) continue;
279 for(l=0;l<nrkev;l++){
280 for(m=0;m<nrkev;m++){
281 if(m==l) continue;
282 for(n=0;n<nrkev;n++){
283 if(n==l ||n==m) continue;
284 kbuf[0] = kevdwn[i];
285 kbuf[1] = kevdwn[j];
286 kbuf[2] = kevdwn[k];
287 kbuf[3] = kevup[l];
288 kbuf[4] = kevup[m];
289 kbuf[5] = kevup[n];
290 do_test( hWnd, count++, kbuf);
300 /* test each set specified in the global testkeyset array */
301 static void TestSysKeys( HWND hWnd)
303 int i;
304 for(i=0; testkeyset[i].nrkev;i++)
305 TestASet( hWnd, testkeyset[i].nrkev, testkeyset[i].keydwn,
306 testkeyset[i].keyup);
309 static LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam,
310 LPARAM lParam )
312 switch (msg) {
313 case WM_USER:
314 SetFocus(hWnd);
315 /* window has focus, now do the test */
316 if( hWnd == hWndTest) TestSysKeys( hWnd);
317 /* finished :-) */
318 break;
320 case WM_DESTROY:
321 PostQuitMessage( 0 );
322 break;
324 default:
325 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
328 return 0;
331 static void test_Input_whitebox(void)
333 MSG msg;
334 WNDCLASSA wclass;
335 HANDLE hInstance = GetModuleHandleA( NULL );
337 wclass.lpszClassName = "InputSysKeyTestClass";
338 wclass.style = CS_HREDRAW | CS_VREDRAW;
339 wclass.lpfnWndProc = WndProc;
340 wclass.hInstance = hInstance;
341 wclass.hIcon = LoadIconA( 0, (LPSTR)IDI_APPLICATION );
342 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW);
343 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1);
344 wclass.lpszMenuName = 0;
345 wclass.cbClsExtra = 0;
346 wclass.cbWndExtra = 0;
347 assert (RegisterClassA( &wclass ));
348 /* create the test window that will receive the keystrokes */
349 assert ( hWndTest = CreateWindowA( wclass.lpszClassName, "InputSysKeyTest",
350 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100,
351 NULL, NULL, hInstance, NULL) );
352 ShowWindow( hWndTest, SW_SHOW);
353 UpdateWindow( hWndTest);
355 /* flush pending messages */
356 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
358 SendMessageA(hWndTest, WM_USER, 0, 0);
359 DestroyWindow(hWndTest);
362 static void empty_message_queue(void) {
363 MSG msg;
364 while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
365 TranslateMessage(&msg);
366 DispatchMessage(&msg);
370 struct transition_s {
371 WORD wVk;
372 BYTE before_state;
375 typedef enum {
376 sent=0x1,
377 posted=0x2,
378 parent=0x4,
379 wparam=0x8,
380 lparam=0x10,
381 defwinproc=0x20,
382 beginpaint=0x40,
383 optional=0x80,
384 hook=0x100,
385 winevent_hook=0x200
386 } msg_flags_t;
388 struct message {
389 UINT message; /* the WM_* code */
390 msg_flags_t flags; /* message props */
391 WPARAM wParam; /* expected value of wParam */
392 LPARAM lParam; /* expected value of lParam */
395 struct sendinput_test_s {
396 WORD wVk;
397 DWORD dwFlags;
398 BOOL _todo_wine;
399 struct transition_s expected_transitions[MAXKEYEVENTS+1];
400 struct message expected_messages[MAXKEYMESSAGES+1];
401 } sendinput_test[] = {
402 /* test ALT+F */
403 {VK_LMENU, 0, 0, {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
404 {{WM_SYSKEYDOWN, hook|wparam, VK_LMENU}, {WM_SYSKEYDOWN}, {0}}},
405 {'F', 0, 0, {{'F', 0x00}, {0}},
406 {{WM_SYSKEYDOWN, hook}, {WM_SYSKEYDOWN},
407 {WM_SYSCHAR},
408 {WM_SYSCOMMAND}, {0}}},
409 {'F', KEYEVENTF_KEYUP, 0, {{'F', 0x80}, {0}},
410 {{WM_SYSKEYUP, hook}, {WM_SYSKEYUP}, {0}}},
411 {VK_LMENU, KEYEVENTF_KEYUP, 0, {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
412 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
414 /* test CTRL+O */
415 {VK_LCONTROL, 0, 0, {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
416 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
417 {'O', 0, 0, {{'O', 0x00}, {0}},
418 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {WM_CHAR}, {0}}},
419 {'O', KEYEVENTF_KEYUP, 0, {{'O', 0x80}, {0}},
420 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
421 {VK_LCONTROL, KEYEVENTF_KEYUP, 0, {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
422 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
424 /* test ALT+CTRL+X */
425 {VK_LMENU, 0, 0, {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
426 {{WM_SYSKEYDOWN, hook}, {WM_SYSKEYDOWN}, {0}}},
427 {VK_LCONTROL, 0, 0, {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
428 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
429 {'X', 0, 0, {{'X', 0x00}, {0}},
430 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
431 {'X', KEYEVENTF_KEYUP, 0, {{'X', 0x80}, {0}},
432 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
433 {VK_LCONTROL, KEYEVENTF_KEYUP, 0, {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
434 {{WM_SYSKEYUP, hook}, {WM_SYSKEYUP}, {0}}},
435 {VK_LMENU, KEYEVENTF_KEYUP, 0, {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
436 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
438 /* test SHIFT+A */
439 {VK_LSHIFT, 0, 0, {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
440 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {0}}},
441 {'A', 0, 0, {{'A', 0x00}, {0}},
442 {{WM_KEYDOWN, hook}, {WM_KEYDOWN}, {WM_CHAR}, {0}}},
443 {'A', KEYEVENTF_KEYUP, 0, {{'A', 0x80}, {0}},
444 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
445 {VK_LSHIFT, KEYEVENTF_KEYUP, 0, {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
446 {{WM_KEYUP, hook}, {WM_KEYUP}, {0}}},
447 /* test L-SHIFT & R-SHIFT: */
448 /* RSHIFT == LSHIFT */
449 {VK_RSHIFT, 0, 0,
450 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
451 {{WM_KEYDOWN, hook|wparam, VK_RSHIFT},
452 {WM_KEYDOWN}, {0}}},
453 {VK_RSHIFT, KEYEVENTF_KEYUP, 0,
454 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
455 {{WM_KEYUP, hook, hook|wparam, VK_RSHIFT},
456 {WM_KEYUP}, {0}}},
458 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
459 {VK_LSHIFT, KEYEVENTF_EXTENDEDKEY, 0,
460 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
461 {{WM_KEYDOWN, hook|wparam|lparam, VK_LSHIFT, LLKHF_EXTENDED},
462 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
463 {VK_LSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
464 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
465 {{WM_KEYUP, hook|wparam|lparam, VK_LSHIFT, LLKHF_UP|LLKHF_EXTENDED},
466 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
467 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
468 {VK_RSHIFT, KEYEVENTF_EXTENDEDKEY, 0,
469 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
470 {{WM_KEYDOWN, hook|wparam|lparam, VK_RSHIFT, LLKHF_EXTENDED},
471 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
472 {VK_RSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
473 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
474 {{WM_KEYUP, hook|wparam|lparam, VK_RSHIFT, LLKHF_UP|LLKHF_EXTENDED},
475 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
476 /* SHIFT == LSHIFT */
477 {VK_SHIFT, 0, 0,
478 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
479 {{WM_KEYDOWN, hook|wparam|lparam, VK_SHIFT, 0},
480 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
481 {VK_SHIFT, KEYEVENTF_KEYUP, 0,
482 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
483 {{WM_KEYUP, hook|wparam|lparam, VK_SHIFT, LLKHF_UP},
484 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
485 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
486 {VK_SHIFT, KEYEVENTF_EXTENDEDKEY, 0,
487 {{VK_SHIFT, 0x00}, {VK_RSHIFT, 0x00}, {0}},
488 {{WM_KEYDOWN, hook|wparam|lparam, VK_SHIFT, LLKHF_EXTENDED},
489 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
490 {VK_SHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
491 {{VK_SHIFT, 0x80}, {VK_RSHIFT, 0x80}, {0}},
492 {{WM_KEYUP, hook|wparam|lparam, VK_SHIFT, LLKHF_UP|LLKHF_EXTENDED},
493 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
495 /* test L-CONTROL & R-CONTROL: */
496 /* RCONTROL == LCONTROL */
497 {VK_RCONTROL, 0, 0,
498 {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
499 {{WM_KEYDOWN, hook|wparam, VK_RCONTROL},
500 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, 0}, {0}}},
501 {VK_RCONTROL, KEYEVENTF_KEYUP, 0,
502 {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
503 {{WM_KEYUP, hook|wparam, VK_RCONTROL},
504 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP}, {0}}},
505 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
506 {VK_LCONTROL, KEYEVENTF_EXTENDEDKEY, 0,
507 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
508 {{WM_KEYDOWN, hook|wparam|lparam, VK_LCONTROL, LLKHF_EXTENDED},
509 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
510 {VK_LCONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
511 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
512 {{WM_KEYUP, hook|wparam|lparam, VK_LCONTROL, LLKHF_UP|LLKHF_EXTENDED},
513 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
514 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
515 {VK_RCONTROL, KEYEVENTF_EXTENDEDKEY, 0,
516 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
517 {{WM_KEYDOWN, hook|wparam|lparam, VK_RCONTROL, LLKHF_EXTENDED},
518 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
519 {VK_RCONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
520 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
521 {{WM_KEYUP, hook|wparam|lparam, VK_RCONTROL, LLKHF_UP|LLKHF_EXTENDED},
522 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
523 /* CONTROL == LCONTROL */
524 {VK_CONTROL, 0, 0,
525 {{VK_CONTROL, 0x00}, {VK_LCONTROL, 0x00}, {0}},
526 {{WM_KEYDOWN, hook|wparam, VK_CONTROL},
527 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, 0}, {0}}},
528 {VK_CONTROL, KEYEVENTF_KEYUP, 0,
529 {{VK_CONTROL, 0x80}, {VK_LCONTROL, 0x80}, {0}},
530 {{WM_KEYUP, hook|wparam, VK_CONTROL},
531 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP}, {0}}},
532 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
533 {VK_CONTROL, KEYEVENTF_EXTENDEDKEY, 0,
534 {{VK_CONTROL, 0x00}, {VK_RCONTROL, 0x00}, {0}},
535 {{WM_KEYDOWN, hook|wparam|lparam, VK_CONTROL, LLKHF_EXTENDED},
536 {WM_KEYDOWN, wparam|lparam, VK_CONTROL, KF_EXTENDED}, {0}}},
537 {VK_CONTROL, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
538 {{VK_CONTROL, 0x80}, {VK_RCONTROL, 0x80}, {0}},
539 {{WM_KEYUP, hook|wparam|lparam, VK_CONTROL, LLKHF_UP|LLKHF_EXTENDED},
540 {WM_KEYUP, wparam|lparam, VK_CONTROL, KF_UP|KF_EXTENDED}, {0}}},
542 /* test L-MENU & R-MENU: */
543 /* RMENU == LMENU */
544 {VK_RMENU, 0, 0,
545 {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
546 {{WM_SYSKEYDOWN, hook|wparam, VK_RMENU},
547 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0}, {0}}},
548 {VK_RMENU, KEYEVENTF_KEYUP, 1,
549 {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
550 {{WM_KEYUP, hook|wparam, VK_RMENU},
551 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP},
552 {WM_SYSCOMMAND}, {0}}},
553 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
554 {VK_LMENU, KEYEVENTF_EXTENDEDKEY, 0,
555 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
556 {{WM_SYSKEYDOWN, hook|wparam|lparam, VK_LMENU, LLKHF_EXTENDED},
557 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
558 {VK_LMENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 1,
559 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
560 {{WM_KEYUP, hook|wparam|lparam, VK_LMENU, LLKHF_UP|LLKHF_EXTENDED},
561 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
562 {WM_SYSCOMMAND}, {0}}},
563 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
564 {VK_RMENU, KEYEVENTF_EXTENDEDKEY, 0,
565 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
566 {{WM_SYSKEYDOWN, hook|wparam|lparam, VK_RMENU, LLKHF_EXTENDED},
567 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
568 {VK_RMENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 1,
569 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
570 {{WM_KEYUP, hook|wparam|lparam, VK_RMENU, LLKHF_UP|LLKHF_EXTENDED},
571 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
572 {WM_SYSCOMMAND}, {0}}},
573 /* MENU == LMENU */
574 {VK_MENU, 0, 0,
575 {{VK_MENU, 0x00}, {VK_LMENU, 0x00}, {0}},
576 {{WM_SYSKEYDOWN, hook|wparam, VK_MENU},
577 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0}, {0}}},
578 {VK_MENU, KEYEVENTF_KEYUP, 1,
579 {{VK_MENU, 0x80}, {VK_LMENU, 0x80}, {0}},
580 {{WM_KEYUP, hook|wparam, VK_MENU},
581 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP},
582 {WM_SYSCOMMAND}, {0}}},
583 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
584 {VK_MENU, KEYEVENTF_EXTENDEDKEY, 0,
585 {{VK_MENU, 0x00}, {VK_RMENU, 0x00}, {0}},
586 {{WM_SYSKEYDOWN, hook|wparam|lparam, VK_MENU, LLKHF_EXTENDED},
587 {WM_SYSKEYDOWN, wparam|lparam, VK_MENU, KF_EXTENDED}, {0}}},
588 {VK_MENU, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 1,
589 {{VK_MENU, 0x80}, {VK_RMENU, 0x80}, {0}},
590 {{WM_KEYUP, hook|wparam|lparam, VK_MENU, LLKHF_UP|LLKHF_EXTENDED},
591 {WM_SYSKEYUP, wparam|lparam, VK_MENU, KF_UP|KF_EXTENDED},
592 {WM_SYSCOMMAND}, {0}}},
594 /* test LSHIFT & RSHIFT */
595 {VK_LSHIFT, 0, 0,
596 {{VK_SHIFT, 0x00}, {VK_LSHIFT, 0x00}, {0}},
597 {{WM_KEYDOWN, hook|wparam|lparam, VK_LSHIFT, 0},
598 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
599 {VK_RSHIFT, KEYEVENTF_EXTENDEDKEY, 0,
600 {{VK_RSHIFT, 0x00}, {0}},
601 {{WM_KEYDOWN, hook|wparam|lparam, VK_RSHIFT, LLKHF_EXTENDED},
602 {WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0}, {0}}},
603 {VK_RSHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, 0,
604 {{VK_RSHIFT, 0x80}, {0}},
605 {{WM_KEYUP, hook|wparam|lparam, VK_RSHIFT, LLKHF_UP|LLKHF_EXTENDED},
606 {WM_KEYUP, optional}, {0}}},
607 {VK_LSHIFT, KEYEVENTF_KEYUP, 0,
608 {{VK_SHIFT, 0x80}, {VK_LSHIFT, 0x80}, {0}},
609 {{WM_KEYUP, hook|wparam, VK_LSHIFT},
610 {WM_KEYUP, wparam|lparam, VK_SHIFT, KF_UP}, {0}}},
612 {0, 0, 0, {{0}}, {{0}}} /* end */
615 static struct message sent_messages[MAXKEYMESSAGES];
616 static UINT sent_messages_cnt;
618 /* Verify that only specified key state transitions occur */
619 static void compare_and_check(int id, BYTE *ks1, BYTE *ks2, struct sendinput_test_s *test)
621 int i, failcount = 0;
622 struct transition_s *t = test->expected_transitions;
623 UINT actual_cnt = 0;
624 const struct message *expected = test->expected_messages;
626 while (t->wVk) {
627 int matched = ((ks1[t->wVk]&0x80) == (t->before_state&0x80)
628 && (ks2[t->wVk]&0x80) == (~t->before_state&0x80));
630 if (!matched && test->_todo_wine)
632 failcount++;
633 todo_wine {
634 ok(matched, "%02d: %02x from %02x -> %02x "
635 "instead of %02x -> %02x\n", id, t->wVk,
636 ks1[t->wVk]&0x80, ks2[t->wVk]&0x80, t->before_state,
637 ~t->before_state&0x80);
639 } else {
640 ok(matched, "%02d: %02x from %02x -> %02x "
641 "instead of %02x -> %02x\n", id, t->wVk,
642 ks1[t->wVk]&0x80, ks2[t->wVk]&0x80, t->before_state,
643 ~t->before_state&0x80);
645 ks2[t->wVk] = ks1[t->wVk]; /* clear the match */
646 t++;
648 for (i = 0; i < 256; i++)
649 if (ks2[i] != ks1[i] && test->_todo_wine)
651 failcount++;
652 todo_wine
653 ok(FALSE, "%02d: %02x from %02x -> %02x unexpected\n", id, i, ks1[i], ks2[i]);
655 else
656 ok(ks2[i] == ks1[i], "%02d: %02x from %02x -> %02x unexpected\n",
657 id, i, ks1[i], ks2[i]);
659 while (expected->message && actual_cnt < sent_messages_cnt)
661 const struct message *actual = &sent_messages[actual_cnt];
663 if (expected->message == actual->message)
665 ok((expected->flags & hook) == (actual->flags & hook),
666 "%x/%x: the msg 0x%04x should have been sent by a hook\n",
667 test->wVk, test->dwFlags, expected->message);
669 if (expected->flags & wparam)
671 if (expected->wParam != actual->wParam && test->_todo_wine)
673 failcount++;
674 todo_wine
675 ok(FALSE, "%x/%x: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
676 test->wVk, test->dwFlags, expected->message, expected->wParam, actual->wParam);
678 else
679 ok(expected->wParam == actual->wParam,
680 "%x/%x: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
681 test->wVk, test->dwFlags, expected->message, expected->wParam, actual->wParam);
683 if (expected->flags & lparam)
685 if (expected->lParam != actual->lParam && test->_todo_wine)
687 failcount++;
688 todo_wine
689 ok(FALSE, "%x/%x: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
690 test->wVk, test->dwFlags, expected->message, expected->lParam, actual->lParam);
692 else
693 ok(expected->lParam == actual->lParam,
694 "%x/%x: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
695 test->wVk, test->dwFlags, expected->message, expected->lParam, actual->lParam);
698 else if (expected->flags & optional)
700 expected++;
701 continue;
703 else if (test->_todo_wine)
705 failcount++;
706 todo_wine
707 ok(FALSE,
708 "%x/%x: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
709 test->wVk, test->dwFlags, expected->message, actual->message);
711 else
712 ok(FALSE,
713 "%x/%x: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
714 test->wVk, test->dwFlags, expected->message, actual->message);
716 actual_cnt++;
717 expected++;
719 /* skip all optional trailing messages */
720 while (expected->message && (expected->flags & optional))
721 expected++;
724 if (expected->message || actual_cnt < sent_messages_cnt)
726 if (test->_todo_wine)
728 failcount++;
729 todo_wine
730 ok(FALSE, "%x/%x: the msg sequence is not complete: expected %04x - actual %04x\n",
731 test->wVk, test->dwFlags, expected->message, sent_messages[actual_cnt].message);
733 else
734 ok(FALSE, "%x/%x: the msg sequence is not complete: expected %04x - actual %04x\n",
735 test->wVk, test->dwFlags, expected->message, sent_messages[actual_cnt].message);
738 if( test->_todo_wine && !failcount) /* succeeded yet marked todo */
739 todo_wine
740 ok(TRUE, "%x/%x: marked \"todo_wine\" but succeeds\n", test->wVk, test->dwFlags);
742 sent_messages_cnt = 0;
745 /* WndProc2 checks that we get at least the messages specified */
746 static LRESULT CALLBACK WndProc2(HWND hWnd, UINT Msg, WPARAM wParam,
747 LPARAM lParam)
749 if (winetest_debug > 1) trace("MSG: %8x W:%8lx L:%8lx\n", Msg, wParam, lParam);
751 if (Msg != WM_PAINT &&
752 Msg != WM_NCPAINT &&
753 Msg != WM_SYNCPAINT &&
754 Msg != WM_ERASEBKGND &&
755 Msg != WM_NCHITTEST &&
756 Msg != WM_GETTEXT &&
757 Msg != WM_GETICON &&
758 Msg != WM_DEVICECHANGE)
760 sent_messages[sent_messages_cnt].message = Msg;
761 sent_messages[sent_messages_cnt].flags = 0;
762 sent_messages[sent_messages_cnt].wParam = wParam;
763 sent_messages[sent_messages_cnt++].lParam = HIWORD(lParam) & (KF_UP|KF_EXTENDED);
765 return DefWindowProc(hWnd, Msg, wParam, lParam);
768 static LRESULT CALLBACK hook_proc(int code, WPARAM wparam, LPARAM lparam)
770 KBDLLHOOKSTRUCT *hook_info = (KBDLLHOOKSTRUCT *)lparam;
772 if (code == HC_ACTION)
774 sent_messages[sent_messages_cnt].message = wparam;
775 sent_messages[sent_messages_cnt].flags = hook;
776 sent_messages[sent_messages_cnt].wParam = hook_info->vkCode;
777 sent_messages[sent_messages_cnt++].lParam = hook_info->flags & (LLKHF_UP|LLKHF_EXTENDED);
779 if(0) /* For some reason not stable on Wine */
781 if (wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN)
782 ok(!(GetAsyncKeyState(hook_info->vkCode) & 0x8000), "key %x should be up\n", hook_info->vkCode);
783 else if (wparam == WM_KEYUP || wparam == WM_SYSKEYUP)
784 ok(GetAsyncKeyState(hook_info->vkCode) & 0x8000, "key %x should be down\n", hook_info->vkCode);
787 if (winetest_debug > 1)
788 trace("Hook: w=%lx vk:%8x sc:%8x fl:%8x %lx\n", wparam,
789 hook_info->vkCode, hook_info->scanCode, hook_info->flags, hook_info->dwExtraInfo);
791 return CallNextHookEx( 0, code, wparam, lparam );
793 static void test_Input_blackbox(void)
795 TEST_INPUT i;
796 int ii;
797 BYTE ks1[256], ks2[256];
798 LONG_PTR prevWndProc;
799 HWND window;
800 HHOOK hook;
802 if (!pSendInput)
804 skip("SendInput is not available\n");
805 return;
808 window = CreateWindow("Static", NULL, WS_POPUP|WS_HSCROLL|WS_VSCROLL
809 |WS_VISIBLE, 0, 0, 200, 60, NULL, NULL,
810 NULL, NULL);
811 ok(window != NULL, "error: %d\n", (int) GetLastError());
813 hook = SetWindowsHookExA(WH_KEYBOARD_LL, hook_proc, GetModuleHandleA( NULL ), 0);
815 /* must process all initial messages, otherwise X11DRV_KeymapNotify unsets
816 * key state set by SendInput(). */
817 empty_message_queue();
819 prevWndProc = SetWindowLongPtr(window, GWLP_WNDPROC, (LONG_PTR) WndProc2);
820 ok(prevWndProc != 0 || (prevWndProc == 0 && GetLastError() == 0),
821 "error: %d\n", (int) GetLastError());
823 i.type = INPUT_KEYBOARD;
824 i.u.ki.time = 0;
825 i.u.ki.dwExtraInfo = 0;
827 for (ii = 0; ii < sizeof(sendinput_test)/sizeof(struct sendinput_test_s)-1;
828 ii++) {
829 GetKeyboardState(ks1);
830 i.u.ki.wScan = ii+1 /* useful for debugging */;
831 i.u.ki.dwFlags = sendinput_test[ii].dwFlags;
832 i.u.ki.wVk = sendinput_test[ii].wVk;
833 pSendInput(1, (INPUT*)&i, sizeof(TEST_INPUT));
834 empty_message_queue();
835 GetKeyboardState(ks2);
836 compare_and_check(ii, ks1, ks2, &sendinput_test[ii]);
839 empty_message_queue();
840 DestroyWindow(window);
841 UnhookWindowsHookEx(hook);
844 static void test_keynames(void)
846 int i, len;
847 char buff[256];
849 for (i = 0; i < 512; i++)
851 strcpy(buff, "----");
852 len = GetKeyNameTextA(i << 16, buff, sizeof(buff));
853 ok(len || !buff[0], "%d: Buffer is not zeroed\n", i);
857 static POINT pt_old, pt_new;
858 static BOOL clipped;
859 #define STEP 20
861 static LRESULT CALLBACK hook_proc1( int code, WPARAM wparam, LPARAM lparam )
863 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
864 POINT pt, pt1;
866 if (code == HC_ACTION)
868 /* This is our new cursor position */
869 pt_new = hook->pt;
870 /* Should return previous position */
871 GetCursorPos(&pt);
872 ok(pt.x == pt_old.x && pt.y == pt_old.y, "GetCursorPos: (%d,%d)\n", pt.x, pt.y);
874 /* Should set new position until hook chain is finished. */
875 pt.x = pt_old.x + STEP;
876 pt.y = pt_old.y + STEP;
877 SetCursorPos(pt.x, pt.y);
878 GetCursorPos(&pt1);
879 if (clipped)
880 ok(pt1.x == pt_old.x && pt1.y == pt_old.y, "Wrong set pos: (%d,%d)\n", pt1.x, pt1.y);
881 else
882 ok(pt1.x == pt.x && pt1.y == pt.y, "Wrong set pos: (%d,%d)\n", pt1.x, pt1.y);
884 return CallNextHookEx( 0, code, wparam, lparam );
887 static LRESULT CALLBACK hook_proc2( int code, WPARAM wparam, LPARAM lparam )
889 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
890 POINT pt;
892 if (code == HC_ACTION)
894 ok(hook->pt.x == pt_new.x && hook->pt.y == pt_new.y,
895 "Wrong hook coords: (%d %d) != (%d,%d)\n", hook->pt.x, hook->pt.y, pt_new.x, pt_new.y);
897 /* Should match position set above */
898 GetCursorPos(&pt);
899 if (clipped)
900 ok(pt.x == pt_old.x && pt.y == pt_old.y, "GetCursorPos: (%d,%d)\n", pt.x, pt.y);
901 else
902 ok(pt.x == pt_old.x +STEP && pt.y == pt_old.y +STEP, "GetCursorPos: (%d,%d)\n", pt.x, pt.y);
904 return CallNextHookEx( 0, code, wparam, lparam );
907 static void test_mouse_ll_hook(void)
909 HWND hwnd;
910 HHOOK hook1, hook2;
911 POINT pt_org, pt;
912 RECT rc;
914 GetCursorPos(&pt_org);
915 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
916 10, 10, 200, 200, NULL, NULL, NULL, NULL);
917 SetCursorPos(100, 100);
919 hook2 = SetWindowsHookExA(WH_MOUSE_LL, hook_proc2, GetModuleHandleA(0), 0);
920 hook1 = SetWindowsHookExA(WH_MOUSE_LL, hook_proc1, GetModuleHandleA(0), 0);
922 GetCursorPos(&pt_old);
923 mouse_event(MOUSEEVENTF_MOVE, -STEP, 0, 0, 0);
924 GetCursorPos(&pt_old);
925 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);
926 mouse_event(MOUSEEVENTF_MOVE, +STEP, 0, 0, 0);
927 GetCursorPos(&pt_old);
928 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);
929 mouse_event(MOUSEEVENTF_MOVE, 0, -STEP, 0, 0);
930 GetCursorPos(&pt_old);
931 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);
932 mouse_event(MOUSEEVENTF_MOVE, 0, +STEP, 0, 0);
933 GetCursorPos(&pt_old);
934 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);
936 SetRect(&rc, 50, 50, 151, 151);
937 ClipCursor(&rc);
938 clipped = TRUE;
940 SetCursorPos(40, 40);
941 GetCursorPos(&pt_old);
942 ok(pt_old.x == 50 && pt_old.y == 50, "Wrong new pos: (%d,%d)\n", pt_new.x, pt_new.y);
943 SetCursorPos(160, 160);
944 GetCursorPos(&pt_old);
945 ok(pt_old.x == 150 && pt_old.y == 150, "Wrong new pos: (%d,%d)\n", pt_new.x, pt_new.y);
946 mouse_event(MOUSEEVENTF_MOVE, +STEP, +STEP, 0, 0);
947 GetCursorPos(&pt_old);
948 ok(pt_old.x == 150 && pt_old.y == 150, "Wrong new pos: (%d,%d)\n", pt_new.x, pt_new.y);
950 clipped = FALSE;
951 pt_new.x = pt_new.y = 150;
952 ClipCursor(NULL);
953 UnhookWindowsHookEx(hook1);
955 /* Now check that mouse buttons do not change mouse position
956 if we don't have MOUSEEVENTF_MOVE flag specified. */
958 /* We reusing the same hook callback, so make it happy */
959 pt_old.x = pt_new.x - STEP;
960 pt_old.y = pt_new.y - STEP;
961 mouse_event(MOUSEEVENTF_LEFTUP, 123, 456, 0, 0);
962 GetCursorPos(&pt);
963 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
964 mouse_event(MOUSEEVENTF_RIGHTUP, 456, 123, 0, 0);
965 GetCursorPos(&pt);
966 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
968 mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, 123, 456, 0, 0);
969 GetCursorPos(&pt);
970 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
971 mouse_event(MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE, 456, 123, 0, 0);
972 GetCursorPos(&pt);
973 ok(pt.x == pt_new.x && pt.y == pt_new.y, "Position changed: (%d,%d)\n", pt.x, pt.y);
975 UnhookWindowsHookEx(hook2);
976 DestroyWindow(hwnd);
977 SetCursorPos(pt_org.x, pt_org.y);
980 static void test_GetMouseMovePointsEx(void)
982 #define BUFLIM 64
983 #define MYERROR 0xdeadbeef
984 int count, retval;
985 MOUSEMOVEPOINT in;
986 MOUSEMOVEPOINT out[200];
987 POINT point;
989 /* Get a valid content for the input struct */
990 if(!GetCursorPos(&point)) {
991 skip("GetCursorPos() failed with error %u\n", GetLastError());
992 return;
994 memset(&in, 0, sizeof(MOUSEMOVEPOINT));
995 in.x = point.x;
996 in.y = point.y;
998 /* test first parameter
999 * everything different than sizeof(MOUSEMOVEPOINT)
1000 * is expected to fail with ERROR_INVALID_PARAMETER
1002 SetLastError(MYERROR);
1003 retval = pGetMouseMovePointsEx(0, &in, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1004 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1005 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1006 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1008 SetLastError(MYERROR);
1009 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)-1, &in, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1010 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1011 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1012 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1014 SetLastError(MYERROR);
1015 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)+1, &in, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1016 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1017 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1018 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1020 /* test second and third parameter
1022 SetLastError(MYERROR);
1023 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), NULL, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1024 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1025 ok(ERROR_NOACCESS == GetLastError(),
1026 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1028 SetLastError(MYERROR);
1029 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, NULL, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1030 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1031 ok(ERROR_NOACCESS == GetLastError(),
1032 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1034 SetLastError(MYERROR);
1035 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), NULL, NULL, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1036 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1037 ok(ERROR_NOACCESS == GetLastError(),
1038 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1040 SetLastError(MYERROR);
1041 count = 0;
1042 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, NULL, count, GMMP_USE_DISPLAY_POINTS);
1043 todo_wine {
1044 ok(retval == count, "expected GetMouseMovePointsEx to succeed, got %d\n", retval);
1045 ok(MYERROR == GetLastError(),
1046 "expected error %d, got %u\n", MYERROR, GetLastError());
1049 /* test fourth parameter
1050 * a value higher than 64 is expected to fail with ERROR_INVALID_PARAMETER
1052 SetLastError(MYERROR);
1053 count = -1;
1054 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, count, GMMP_USE_DISPLAY_POINTS);
1055 ok(retval == count, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1056 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1057 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1059 SetLastError(MYERROR);
1060 count = 0;
1061 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, count, GMMP_USE_DISPLAY_POINTS);
1062 todo_wine {
1063 ok(retval == count, "expected GetMouseMovePointsEx to succeed, got %d\n", retval);
1064 ok(MYERROR == GetLastError(),
1065 "expected error %d, got %u\n", MYERROR, GetLastError());
1068 SetLastError(MYERROR);
1069 count = BUFLIM;
1070 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, count, GMMP_USE_DISPLAY_POINTS);
1071 todo_wine {
1072 ok((0 <= retval) && (retval <= count), "expected GetMouseMovePointsEx to succeed, got %d\n", retval);
1073 ok(MYERROR == GetLastError(),
1074 "expected error %d, got %u\n", MYERROR, GetLastError());
1077 SetLastError(MYERROR);
1078 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, out, BUFLIM+1, GMMP_USE_DISPLAY_POINTS);
1079 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1080 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1081 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1083 /* it was not possible to force an error with the fifth parameter on win2k */
1085 /* test combinations of wrong parameters to see which error wins */
1086 SetLastError(MYERROR);
1087 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)-1, NULL, out, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1088 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1089 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1090 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1092 SetLastError(MYERROR);
1093 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT)-1, &in, NULL, BUFLIM, GMMP_USE_DISPLAY_POINTS);
1094 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1095 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1096 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1098 SetLastError(MYERROR);
1099 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), NULL, out, BUFLIM+1, GMMP_USE_DISPLAY_POINTS);
1100 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1101 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1102 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1104 SetLastError(MYERROR);
1105 retval = pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT), &in, NULL, BUFLIM+1, GMMP_USE_DISPLAY_POINTS);
1106 ok(retval == -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval);
1107 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1108 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1110 #undef BUFLIM
1111 #undef MYERROR
1114 static void test_key_map(void)
1116 HKL kl = GetKeyboardLayout(0);
1117 UINT kL, kR, s, sL;
1119 s = MapVirtualKeyEx(VK_SHIFT, MAPVK_VK_TO_VSC, kl);
1120 ok(s != 0, "MapVirtualKeyEx(VK_SHIFT) should return non-zero\n");
1121 sL = MapVirtualKeyEx(VK_LSHIFT, MAPVK_VK_TO_VSC, kl);
1122 ok(s == sL, "%x != %x\n", s, sL);
1124 kL = MapVirtualKeyEx(0x2a, MAPVK_VSC_TO_VK, kl);
1125 ok(kL == VK_SHIFT, "Scan code -> vKey = %x (not VK_SHIFT)\n", kL);
1126 kR = MapVirtualKeyEx(0x36, MAPVK_VSC_TO_VK, kl);
1127 ok(kR == VK_SHIFT, "Scan code -> vKey = %x (not VK_SHIFT)\n", kR);
1129 kL = MapVirtualKeyEx(0x2a, MAPVK_VSC_TO_VK_EX, kl);
1130 ok(kL == VK_LSHIFT, "Scan code -> vKey = %x (not VK_LSHIFT)\n", kL);
1131 kR = MapVirtualKeyEx(0x36, MAPVK_VSC_TO_VK_EX, kl);
1132 ok(kR == VK_RSHIFT, "Scan code -> vKey = %x (not VK_RSHIFT)\n", kR);
1135 START_TEST(input)
1137 init_function_pointers();
1139 if (!pSendInput)
1140 skip("SendInput is not available\n");
1141 else
1142 test_Input_whitebox();
1144 test_Input_blackbox();
1145 test_keynames();
1146 test_mouse_ll_hook();
1147 test_key_map();
1149 if(pGetMouseMovePointsEx)
1150 test_GetMouseMovePointsEx();
1151 else
1152 skip("GetMouseMovePointsEx is not available\n");