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
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 */
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
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
54 #include "wine/test.h"
58 static long timetag
= 0x10000000;
60 static UINT (WINAPI
*pSendInput
) (UINT
, INPUT
*, size_t);
61 static int (WINAPI
*pGetMouseMovePointsEx
) (UINT
, LPMOUSEMOVEPOINT
, LPMOUSEMOVEPOINT
, int, DWORD
);
63 #define MAXKEYEVENTS 6
64 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
65 and only one message */
67 /* keyboard message names, sorted as their value */
68 static const char *MSGNAME
[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
69 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
71 /* keyevents, add more as needed */
73 { ALTDOWN
= 1, ALTUP
, XDOWN
, XUP
, SHIFTDOWN
, SHIFTUP
, CTRLDOWN
, CTRLUP
} KEV
;
75 static const int GETVKEY
[]={0, VK_MENU
, VK_MENU
, 'X', 'X', VK_SHIFT
, VK_SHIFT
, VK_CONTROL
, VK_CONTROL
};
76 /* matching scan codes */
77 static const int GETSCAN
[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
78 /* matching updown events */
79 static const int GETFLAGS
[]={0, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
};
80 /* matching descriptions */
81 static const char *getdesc
[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
83 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
95 #define ADDTOINPUTS(kev) \
96 inputs[evtctr].type = INPUT_KEYBOARD; \
97 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
98 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
99 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETFLAGS[ kev]; \
100 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
101 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
110 /*******************************************
111 * add new test sets here
112 * the software will make all combinations of the
113 * keyevent defined here
115 static const struct {
117 KEV keydwn
[MAXKEYEVENTS
];
118 KEV keyup
[MAXKEYEVENTS
];
120 { 2, { ALTDOWN
, XDOWN
}, { ALTUP
, XUP
}},
121 { 3, { ALTDOWN
, XDOWN
, SHIFTDOWN
}, { ALTUP
, XUP
, SHIFTUP
}},
122 { 3, { ALTDOWN
, XDOWN
, CTRLDOWN
}, { ALTUP
, XUP
, CTRLUP
}},
123 { 3, { SHIFTDOWN
, XDOWN
, CTRLDOWN
}, { SHIFTUP
, XUP
, CTRLUP
}},
124 { 0 } /* mark the end */
127 /**********************adapted from input.c **********************************/
129 static BYTE InputKeyStateTable
[256];
130 static BYTE AsyncKeyStateTable
[256];
131 static BYTE TrackSysKey
= 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
132 or a WM_KEYUP message */
134 static void init_function_pointers(void)
136 HMODULE hdll
= GetModuleHandleA("user32");
138 #define GET_PROC(func) \
139 p ## func = (void*)GetProcAddress(hdll, #func); \
141 trace("GetProcAddress(%s) failed\n", #func);
144 GET_PROC(GetMouseMovePointsEx
)
149 static int KbdMessage( KEV kev
, WPARAM
*pwParam
, LPARAM
*plParam
)
152 int VKey
= GETVKEY
[kev
];
155 flags
= LOBYTE(GETSCAN
[kev
]);
156 if (GETFLAGS
[kev
] & KEYEVENTF_EXTENDEDKEY
) flags
|= KF_EXTENDED
;
158 if (GETFLAGS
[kev
] & KEYEVENTF_KEYUP
)
161 if( (InputKeyStateTable
[VK_MENU
] & 0x80) && (
162 (VKey
== VK_MENU
) || (VKey
== VK_CONTROL
) ||
163 !(InputKeyStateTable
[VK_CONTROL
] & 0x80))) {
164 if( TrackSysKey
== VK_MENU
|| /* <ALT>-down/<ALT>-up sequence */
165 (VKey
!= VK_MENU
)) /* <ALT>-down...<something else>-up */
166 message
= WM_SYSKEYUP
;
169 InputKeyStateTable
[VKey
] &= ~0x80;
170 flags
|= KF_REPEAT
| KF_UP
;
174 if (InputKeyStateTable
[VKey
] & 0x80) flags
|= KF_REPEAT
;
175 if (!(InputKeyStateTable
[VKey
] & 0x80)) InputKeyStateTable
[VKey
] ^= 0x01;
176 InputKeyStateTable
[VKey
] |= 0x80;
177 AsyncKeyStateTable
[VKey
] |= 0x80;
179 message
= WM_KEYDOWN
;
180 if( (InputKeyStateTable
[VK_MENU
] & 0x80) &&
181 !(InputKeyStateTable
[VK_CONTROL
] & 0x80)) {
182 message
= WM_SYSKEYDOWN
;
187 if (InputKeyStateTable
[VK_MENU
] & 0x80) flags
|= KF_ALTDOWN
;
189 if( plParam
) *plParam
= MAKELPARAM( 1, flags
);
190 if( pwParam
) *pwParam
= VKey
;
194 /****************************** end copy input.c ****************************/
197 * . prepare the keyevents for SendInputs
198 * . calculate the "expected" messages
199 * . Send the events to our window
200 * . retrieve the messages from the input queue
203 static void do_test( HWND hwnd
, int seqnr
, const KEV td
[] )
205 INPUT inputs
[MAXKEYEVENTS
];
206 KMSG expmsg
[MAXKEYEVENTS
];
213 TrackSysKey
=0; /* see input.c */
214 for( i
= 0; i
< MAXKEYEVENTS
; i
++) {
216 strcat(buf
, getdesc
[td
[i
]]);
218 expmsg
[i
].message
= KbdMessage(td
[i
], &(expmsg
[i
].wParam
), &(expmsg
[i
].lParam
)); /* see queue_kbd_event() */
220 expmsg
[i
].message
= 0;
222 for( kmctr
= 0; kmctr
< MAXKEYEVENTS
&& expmsg
[kmctr
].message
; kmctr
++)
224 assert( evtctr
<= MAXKEYEVENTS
);
225 assert( evtctr
== pSendInput(evtctr
, &inputs
[0], sizeof(INPUT
)));
227 if (winetest_debug
> 1)
228 trace("======== key stroke sequence #%d: %s =============\n",
230 while( PeekMessage(&msg
,hwnd
,WM_KEYFIRST
,WM_KEYLAST
,PM_REMOVE
) ) {
231 if (winetest_debug
> 1)
232 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i
,
233 MSGNAME
[msg
.message
- WM_KEYFIRST
], msg
.wParam
, msg
.lParam
, msg
.time
);
235 ok( msg
.message
== expmsg
[i
].message
&&
236 msg
.wParam
== expmsg
[i
].wParam
&&
237 msg
.lParam
== expmsg
[i
].lParam
,
238 "wrong message! expected:\n"
239 "message[%d] %-15s wParam %04lx lParam %08lx\n",i
,
240 MSGNAME
[(expmsg
[i
]).message
- WM_KEYFIRST
],
241 expmsg
[i
].wParam
, expmsg
[i
].lParam
);
245 if (winetest_debug
> 1)
246 trace("%d messages retrieved\n", i
);
247 ok( i
== kmctr
, "message count is wrong: got %d expected: %d\n", i
, kmctr
);
250 /* test all combinations of the specified key events */
251 static void TestASet( HWND hWnd
, int nrkev
, const KEV kevdwn
[], const KEV kevup
[] )
255 KEV kbuf
[MAXKEYEVENTS
];
256 assert( nrkev
==2 || nrkev
==3);
257 for(i
=0;i
<MAXKEYEVENTS
;i
++) kbuf
[i
]=0;
258 /* two keys involved gives 4 test cases */
260 for(i
=0;i
<nrkev
;i
++) {
261 for(j
=0;j
<nrkev
;j
++) {
263 kbuf
[1] = kevdwn
[1-i
];
265 kbuf
[3] = kevup
[1-j
];
266 do_test( hWnd
, count
++, kbuf
);
270 /* three keys involved gives 36 test cases */
272 for(i
=0;i
<nrkev
;i
++){
273 for(j
=0;j
<nrkev
;j
++){
275 for(k
=0;k
<nrkev
;k
++){
276 if(k
==i
|| k
==j
) continue;
277 for(l
=0;l
<nrkev
;l
++){
278 for(m
=0;m
<nrkev
;m
++){
280 for(n
=0;n
<nrkev
;n
++){
281 if(n
==l
||n
==m
) continue;
288 do_test( hWnd
, count
++, kbuf
);
298 /* test each set specified in the global testkeyset array */
299 static void TestSysKeys( HWND hWnd
)
302 for(i
=0; testkeyset
[i
].nrkev
;i
++)
303 TestASet( hWnd
, testkeyset
[i
].nrkev
, testkeyset
[i
].keydwn
,
304 testkeyset
[i
].keyup
);
307 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
313 /* window has focus, now do the test */
314 if( hWnd
== hWndTest
) TestSysKeys( hWnd
);
319 PostQuitMessage( 0 );
323 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
329 static void test_Input_whitebox(void)
333 HANDLE hInstance
= GetModuleHandleA( NULL
);
335 wclass
.lpszClassName
= "InputSysKeyTestClass";
336 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
337 wclass
.lpfnWndProc
= WndProc
;
338 wclass
.hInstance
= hInstance
;
339 wclass
.hIcon
= LoadIconA( 0, (LPSTR
)IDI_APPLICATION
);
340 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
341 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1);
342 wclass
.lpszMenuName
= 0;
343 wclass
.cbClsExtra
= 0;
344 wclass
.cbWndExtra
= 0;
345 assert (RegisterClassA( &wclass
));
346 /* create the test window that will receive the keystrokes */
347 assert ( hWndTest
= CreateWindowA( wclass
.lpszClassName
, "InputSysKeyTest",
348 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
349 NULL
, NULL
, hInstance
, NULL
) );
350 ShowWindow( hWndTest
, SW_SHOW
);
351 UpdateWindow( hWndTest
);
353 /* flush pending messages */
354 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
356 SendMessageA(hWndTest
, WM_USER
, 0, 0);
357 DestroyWindow(hWndTest
);
360 /* try to make sure pending X events have been processed before continuing */
361 static void empty_message_queue(void)
365 int min_timeout
= 50;
366 DWORD time
= GetTickCount() + diff
;
370 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
371 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
373 TranslateMessage(&msg
);
374 DispatchMessage(&msg
);
376 diff
= time
- GetTickCount();
381 struct transition_s
{
401 UINT message
; /* the WM_* code */
402 msg_flags_t flags
; /* message props */
403 WPARAM wParam
; /* expected value of wParam */
404 LPARAM lParam
; /* expected value of lParam */
407 struct sendinput_test_s
{
411 struct transition_s expected_transitions
[MAXKEYEVENTS
+1];
412 struct message expected_messages
[MAXKEYMESSAGES
+1];
413 } sendinput_test
[] = {
416 {VK_LMENU
, 0, 0, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
417 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_LMENU
}, {WM_SYSKEYDOWN
}, {0}}},
418 {'F', 0, 0, {{'F', 0x00}, {0}},
419 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
},
421 {WM_SYSCOMMAND
}, {0}}},
422 {'F', KEYEVENTF_KEYUP
, 0, {{'F', 0x80}, {0}},
423 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
424 {VK_LMENU
, KEYEVENTF_KEYUP
, 0, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
425 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
429 {VK_LCONTROL
, 0, 0, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
430 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
431 {'O', 0, 0, {{'O', 0x00}, {0}},
432 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
433 {'O', KEYEVENTF_KEYUP
, 0, {{'O', 0x80}, {0}},
434 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
435 {VK_LCONTROL
, KEYEVENTF_KEYUP
, 0, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
436 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
438 /* test ALT+CTRL+X */
440 {VK_LMENU
, 0, 0, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
441 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
}, {0}}},
442 {VK_LCONTROL
, 0, 0, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
443 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
444 {'X', 0, 0, {{'X', 0x00}, {0}},
445 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
446 {'X', KEYEVENTF_KEYUP
, 0, {{'X', 0x80}, {0}},
447 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
448 {VK_LCONTROL
, KEYEVENTF_KEYUP
, 0, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
449 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
450 {VK_LMENU
, KEYEVENTF_KEYUP
, 0, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
451 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
455 {VK_LSHIFT
, 0, 0, {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
456 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
457 {'A', 0, 0, {{'A', 0x00}, {0}},
458 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
459 {'A', KEYEVENTF_KEYUP
, 0, {{'A', 0x80}, {0}},
460 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
461 {VK_LSHIFT
, KEYEVENTF_KEYUP
, 0, {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
462 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
463 /* test L-SHIFT & R-SHIFT: */
464 /* RSHIFT == LSHIFT */
467 /* recent windows versions (>= w2k3) correctly report an RSHIFT transition */
468 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00, TRUE
}, {VK_RSHIFT
, 0x00, TRUE
}, {0}},
469 {{WM_KEYDOWN
, hook
|wparam
, VK_RSHIFT
},
471 {VK_RSHIFT
, KEYEVENTF_KEYUP
, 0,
472 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80, TRUE
}, {VK_RSHIFT
, 0x80, TRUE
}, {0}},
473 {{WM_KEYUP
, hook
, hook
|wparam
, VK_RSHIFT
},
476 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
478 {VK_LSHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
479 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
480 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_EXTENDED
},
481 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
482 {VK_LSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
483 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
484 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
485 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
486 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
488 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
489 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
490 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
491 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
492 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
493 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
494 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
495 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
497 /* Note about wparam for hook with generic key (VK_SHIFT, VK_CONTROL, VK_MENU):
498 win2k - sends to hook whatever we generated here
499 winXP+ - Attempts to convert key to L/R key but not always correct
501 /* SHIFT == LSHIFT */
504 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
505 {{WM_KEYDOWN
, hook
/* |wparam */|lparam
, VK_SHIFT
, 0},
506 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
507 {VK_SHIFT
, KEYEVENTF_KEYUP
, 0,
508 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
509 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_UP
},
510 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
511 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
513 {VK_SHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
514 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
515 {{WM_KEYDOWN
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_EXTENDED
},
516 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
517 {VK_SHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
518 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
519 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
520 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
522 /* test L-CONTROL & R-CONTROL: */
523 /* RCONTROL == LCONTROL */
526 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
527 {{WM_KEYDOWN
, hook
|wparam
, VK_RCONTROL
},
528 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
529 {VK_RCONTROL
, KEYEVENTF_KEYUP
, 0,
530 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
531 {{WM_KEYUP
, hook
|wparam
, VK_RCONTROL
},
532 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
533 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
535 {VK_LCONTROL
, KEYEVENTF_EXTENDEDKEY
, 0,
536 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
537 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_EXTENDED
},
538 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
539 {VK_LCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
540 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
541 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
542 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
543 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
545 {VK_RCONTROL
, KEYEVENTF_EXTENDEDKEY
, 0,
546 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
547 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_EXTENDED
},
548 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
549 {VK_RCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
550 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
551 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
552 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
553 /* CONTROL == LCONTROL */
556 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
557 {{WM_KEYDOWN
, hook
/*|wparam, VK_CONTROL*/},
558 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
559 {VK_CONTROL
, KEYEVENTF_KEYUP
, 0,
560 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
561 {{WM_KEYUP
, hook
/*|wparam, VK_CONTROL*/},
562 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
563 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
565 {VK_CONTROL
, KEYEVENTF_EXTENDEDKEY
, 0,
566 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
567 {{WM_KEYDOWN
, hook
/*|wparam*/|lparam
, VK_CONTROL
, LLKHF_EXTENDED
},
568 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
569 {VK_CONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
570 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
571 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_CONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
572 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
574 /* test L-MENU & R-MENU: */
578 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
579 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_RMENU
},
580 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
581 {VK_RMENU
, KEYEVENTF_KEYUP
, 1,
582 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
583 {{WM_KEYUP
, hook
|wparam
, VK_RMENU
},
584 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
585 {WM_SYSCOMMAND
}, {0}}},
586 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
588 {VK_LMENU
, KEYEVENTF_EXTENDEDKEY
, 0,
589 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
590 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_EXTENDED
},
591 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
592 {VK_LMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 1,
593 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
594 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
595 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
596 {WM_SYSCOMMAND
}, {0}}},
597 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
599 {VK_RMENU
, KEYEVENTF_EXTENDEDKEY
, 0,
600 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
601 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_EXTENDED
},
602 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
603 {VK_RMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 1,
604 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
605 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
606 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
607 {WM_SYSCOMMAND
}, {0}}},
611 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
612 {{WM_SYSKEYDOWN
, hook
/*|wparam, VK_MENU*/},
613 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
614 {VK_MENU
, KEYEVENTF_KEYUP
, 1,
615 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
616 {{WM_KEYUP
, hook
/*|wparam, VK_MENU*/},
617 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
618 {WM_SYSCOMMAND
}, {0}}},
619 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
621 {VK_MENU
, KEYEVENTF_EXTENDEDKEY
, 0,
622 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
623 {{WM_SYSKEYDOWN
, hook
/*|wparam*/|lparam
, VK_MENU
, LLKHF_EXTENDED
},
624 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
625 {VK_MENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 1,
626 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
627 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_MENU
, LLKHF_UP
|LLKHF_EXTENDED
},
628 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
629 {WM_SYSCOMMAND
}, {0}}},
631 /* test LSHIFT & RSHIFT */
634 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
635 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, 0},
636 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
637 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
638 {{VK_RSHIFT
, 0x00}, {0}},
639 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
640 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
641 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
642 {{VK_RSHIFT
, 0x80}, {0}},
643 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
644 {WM_KEYUP
, optional
}, {0}}},
645 {VK_LSHIFT
, KEYEVENTF_KEYUP
, 0,
646 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
647 {{WM_KEYUP
, hook
|wparam
, VK_LSHIFT
},
648 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
650 {0, 0, 0, {{0}}, {{0}}} /* end */
653 static struct message sent_messages
[MAXKEYMESSAGES
];
654 static UINT sent_messages_cnt
;
656 /* Verify that only specified key state transitions occur */
657 static void compare_and_check(int id
, BYTE
*ks1
, BYTE
*ks2
, struct sendinput_test_s
*test
)
659 int i
, failcount
= 0;
660 struct transition_s
*t
= test
->expected_transitions
;
662 const struct message
*expected
= test
->expected_messages
;
665 int matched
= ((ks1
[t
->wVk
]&0x80) == (t
->before_state
&0x80)
666 && (ks2
[t
->wVk
]&0x80) == (~t
->before_state
&0x80));
668 if (!matched
&& test
->_todo_wine
)
672 ok(matched
, "%2d (%x/%x): %02x from %02x -> %02x "
673 "instead of %02x -> %02x\n", id
, test
->wVk
, test
->dwFlags
,
674 t
->wVk
, ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
675 ~t
->before_state
&0x80);
678 ok(matched
|| t
->optional
, "%2d (%x/%x): %02x from %02x -> %02x "
679 "instead of %02x -> %02x\n", id
, test
->wVk
, test
->dwFlags
,
680 t
->wVk
, ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
681 ~t
->before_state
&0x80);
683 ks2
[t
->wVk
] = ks1
[t
->wVk
]; /* clear the match */
686 for (i
= 0; i
< 256; i
++)
687 if (ks2
[i
] != ks1
[i
] && test
->_todo_wine
)
691 ok(FALSE
, "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
692 id
, test
->wVk
, test
->dwFlags
, i
, ks1
[i
], ks2
[i
]);
695 ok(ks2
[i
] == ks1
[i
], "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
696 id
, test
->wVk
, test
->dwFlags
, i
, ks1
[i
], ks2
[i
]);
698 while (expected
->message
&& actual_cnt
< sent_messages_cnt
)
700 const struct message
*actual
= &sent_messages
[actual_cnt
];
702 if (expected
->message
== actual
->message
)
704 ok((expected
->flags
& hook
) == (actual
->flags
& hook
),
705 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
706 id
, test
->wVk
, test
->dwFlags
, expected
->message
);
708 if (expected
->flags
& wparam
)
710 if (expected
->wParam
!= actual
->wParam
&& test
->_todo_wine
)
714 ok(FALSE
, "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
715 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
718 ok(expected
->wParam
== actual
->wParam
,
719 "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
720 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
722 if (expected
->flags
& lparam
)
724 if (expected
->lParam
!= actual
->lParam
&& test
->_todo_wine
)
728 ok(FALSE
, "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
729 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
732 ok(expected
->lParam
== actual
->lParam
,
733 "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
734 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
737 else if (expected
->flags
& optional
)
742 else if (test
->_todo_wine
)
747 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
748 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
752 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
753 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
758 /* skip all optional trailing messages */
759 while (expected
->message
&& (expected
->flags
& optional
))
763 if (expected
->message
|| actual_cnt
< sent_messages_cnt
)
765 if (test
->_todo_wine
)
769 ok(FALSE
, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
770 id
, test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
773 ok(FALSE
, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
774 id
, test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
777 if( test
->_todo_wine
&& !failcount
) /* succeeded yet marked todo */
779 ok(TRUE
, "%2d (%x/%x): marked \"todo_wine\" but succeeds\n", id
, test
->wVk
, test
->dwFlags
);
781 sent_messages_cnt
= 0;
784 /* WndProc2 checks that we get at least the messages specified */
785 static LRESULT CALLBACK
WndProc2(HWND hWnd
, UINT Msg
, WPARAM wParam
,
788 if (winetest_debug
> 1) trace("MSG: %8x W:%8lx L:%8lx\n", Msg
, wParam
, lParam
);
790 if (Msg
!= WM_PAINT
&&
792 Msg
!= WM_SYNCPAINT
&&
793 Msg
!= WM_ERASEBKGND
&&
794 Msg
!= WM_NCHITTEST
&&
797 Msg
!= WM_DEVICECHANGE
)
799 sent_messages
[sent_messages_cnt
].message
= Msg
;
800 sent_messages
[sent_messages_cnt
].flags
= 0;
801 sent_messages
[sent_messages_cnt
].wParam
= wParam
;
802 sent_messages
[sent_messages_cnt
++].lParam
= HIWORD(lParam
) & (KF_UP
|KF_EXTENDED
);
804 return DefWindowProc(hWnd
, Msg
, wParam
, lParam
);
807 static LRESULT CALLBACK
hook_proc(int code
, WPARAM wparam
, LPARAM lparam
)
809 KBDLLHOOKSTRUCT
*hook_info
= (KBDLLHOOKSTRUCT
*)lparam
;
811 if (code
== HC_ACTION
)
813 sent_messages
[sent_messages_cnt
].message
= wparam
;
814 sent_messages
[sent_messages_cnt
].flags
= hook
;
815 sent_messages
[sent_messages_cnt
].wParam
= hook_info
->vkCode
;
816 sent_messages
[sent_messages_cnt
++].lParam
= hook_info
->flags
& (LLKHF_UP
|LLKHF_EXTENDED
);
818 if(0) /* For some reason not stable on Wine */
820 if (wparam
== WM_KEYDOWN
|| wparam
== WM_SYSKEYDOWN
)
821 ok(!(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000), "key %x should be up\n", hook_info
->vkCode
);
822 else if (wparam
== WM_KEYUP
|| wparam
== WM_SYSKEYUP
)
823 ok(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000, "key %x should be down\n", hook_info
->vkCode
);
826 if (winetest_debug
> 1)
827 trace("Hook: w=%lx vk:%8x sc:%8x fl:%8x %lx\n", wparam
,
828 hook_info
->vkCode
, hook_info
->scanCode
, hook_info
->flags
, hook_info
->dwExtraInfo
);
830 return CallNextHookEx( 0, code
, wparam
, lparam
);
832 static void test_Input_blackbox(void)
836 BYTE ks1
[256], ks2
[256];
837 LONG_PTR prevWndProc
;
843 skip("SendInput is not available\n");
847 window
= CreateWindow("Static", NULL
, WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
848 |WS_VISIBLE
, 0, 0, 200, 60, NULL
, NULL
,
850 ok(window
!= NULL
, "error: %d\n", (int) GetLastError());
852 hook
= SetWindowsHookExA(WH_KEYBOARD_LL
, hook_proc
, GetModuleHandleA( NULL
), 0);
854 /* must process all initial messages, otherwise X11DRV_KeymapNotify unsets
855 * key state set by SendInput(). */
856 empty_message_queue();
858 prevWndProc
= SetWindowLongPtr(window
, GWLP_WNDPROC
, (LONG_PTR
) WndProc2
);
859 ok(prevWndProc
!= 0 || (prevWndProc
== 0 && GetLastError() == 0),
860 "error: %d\n", (int) GetLastError());
862 i
.type
= INPUT_KEYBOARD
;
864 i
.u
.ki
.dwExtraInfo
= 0;
866 for (ii
= 0; ii
< sizeof(sendinput_test
)/sizeof(struct sendinput_test_s
)-1;
868 GetKeyboardState(ks1
);
869 i
.u
.ki
.wScan
= ii
+1 /* useful for debugging */;
870 i
.u
.ki
.dwFlags
= sendinput_test
[ii
].dwFlags
;
871 i
.u
.ki
.wVk
= sendinput_test
[ii
].wVk
;
872 pSendInput(1, (INPUT
*)&i
, sizeof(TEST_INPUT
));
873 empty_message_queue();
874 GetKeyboardState(ks2
);
875 compare_and_check(ii
, ks1
, ks2
, &sendinput_test
[ii
]);
878 empty_message_queue();
879 DestroyWindow(window
);
880 UnhookWindowsHookEx(hook
);
883 static void test_keynames(void)
888 for (i
= 0; i
< 512; i
++)
890 strcpy(buff
, "----");
891 len
= GetKeyNameTextA(i
<< 16, buff
, sizeof(buff
));
892 ok(len
|| !buff
[0], "%d: Buffer is not zeroed\n", i
);
896 static POINT pt_old
, pt_new
;
900 static LRESULT CALLBACK
hook_proc1( int code
, WPARAM wparam
, LPARAM lparam
)
902 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
905 if (code
== HC_ACTION
)
907 /* This is our new cursor position */
909 /* Should return previous position */
911 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
913 /* Should set new position until hook chain is finished. */
914 pt
.x
= pt_old
.x
+ STEP
;
915 pt
.y
= pt_old
.y
+ STEP
;
916 SetCursorPos(pt
.x
, pt
.y
);
919 ok(pt1
.x
== pt_old
.x
&& pt1
.y
== pt_old
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
921 ok(pt1
.x
== pt
.x
&& pt1
.y
== pt
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
923 return CallNextHookEx( 0, code
, wparam
, lparam
);
926 static LRESULT CALLBACK
hook_proc2( int code
, WPARAM wparam
, LPARAM lparam
)
928 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
931 if (code
== HC_ACTION
)
933 ok(hook
->pt
.x
== pt_new
.x
&& hook
->pt
.y
== pt_new
.y
,
934 "Wrong hook coords: (%d %d) != (%d,%d)\n", hook
->pt
.x
, hook
->pt
.y
, pt_new
.x
, pt_new
.y
);
936 /* Should match position set above */
939 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
941 ok(pt
.x
== pt_old
.x
+STEP
&& pt
.y
== pt_old
.y
+STEP
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
943 return CallNextHookEx( 0, code
, wparam
, lparam
);
946 static void test_mouse_ll_hook(void)
953 GetCursorPos(&pt_org
);
954 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
955 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
956 SetCursorPos(100, 100);
958 hook2
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc2
, GetModuleHandleA(0), 0);
959 hook1
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc1
, GetModuleHandleA(0), 0);
961 GetCursorPos(&pt_old
);
962 mouse_event(MOUSEEVENTF_MOVE
, -STEP
, 0, 0, 0);
963 GetCursorPos(&pt_old
);
964 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
);
965 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, 0, 0, 0);
966 GetCursorPos(&pt_old
);
967 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
);
968 mouse_event(MOUSEEVENTF_MOVE
, 0, -STEP
, 0, 0);
969 GetCursorPos(&pt_old
);
970 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
);
971 mouse_event(MOUSEEVENTF_MOVE
, 0, +STEP
, 0, 0);
972 GetCursorPos(&pt_old
);
973 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
);
975 SetRect(&rc
, 50, 50, 151, 151);
979 SetCursorPos(40, 40);
980 GetCursorPos(&pt_old
);
981 ok(pt_old
.x
== 50 && pt_old
.y
== 50, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
982 SetCursorPos(160, 160);
983 GetCursorPos(&pt_old
);
984 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
985 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, +STEP
, 0, 0);
986 GetCursorPos(&pt_old
);
987 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
990 pt_new
.x
= pt_new
.y
= 150;
992 UnhookWindowsHookEx(hook1
);
994 /* Now check that mouse buttons do not change mouse position
995 if we don't have MOUSEEVENTF_MOVE flag specified. */
997 /* We reusing the same hook callback, so make it happy */
998 pt_old
.x
= pt_new
.x
- STEP
;
999 pt_old
.y
= pt_new
.y
- STEP
;
1000 mouse_event(MOUSEEVENTF_LEFTUP
, 123, 456, 0, 0);
1002 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1003 mouse_event(MOUSEEVENTF_RIGHTUP
, 456, 123, 0, 0);
1005 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1007 mouse_event(MOUSEEVENTF_LEFTUP
| MOUSEEVENTF_ABSOLUTE
, 123, 456, 0, 0);
1009 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1010 mouse_event(MOUSEEVENTF_RIGHTUP
| MOUSEEVENTF_ABSOLUTE
, 456, 123, 0, 0);
1012 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1014 UnhookWindowsHookEx(hook2
);
1015 DestroyWindow(hwnd
);
1016 SetCursorPos(pt_org
.x
, pt_org
.y
);
1019 static void test_GetMouseMovePointsEx(void)
1022 #define MYERROR 0xdeadbeef
1025 MOUSEMOVEPOINT out
[200];
1028 /* Get a valid content for the input struct */
1029 if(!GetCursorPos(&point
)) {
1030 skip("GetCursorPos() failed with error %u\n", GetLastError());
1033 memset(&in
, 0, sizeof(MOUSEMOVEPOINT
));
1037 /* test first parameter
1038 * everything different than sizeof(MOUSEMOVEPOINT)
1039 * is expected to fail with ERROR_INVALID_PARAMETER
1041 SetLastError(MYERROR
);
1042 retval
= pGetMouseMovePointsEx(0, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1043 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1044 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1045 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1047 SetLastError(MYERROR
);
1048 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1049 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1050 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1051 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1053 SetLastError(MYERROR
);
1054 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)+1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1055 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1056 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1057 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1059 /* test second and third parameter
1061 SetLastError(MYERROR
);
1062 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1063 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1064 ok(GetLastError() == ERROR_NOACCESS
|| GetLastError() == MYERROR
,
1065 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1067 SetLastError(MYERROR
);
1068 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1069 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1070 ok(ERROR_NOACCESS
== GetLastError(),
1071 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1073 SetLastError(MYERROR
);
1074 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1075 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1076 ok(ERROR_NOACCESS
== GetLastError(),
1077 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1079 SetLastError(MYERROR
);
1081 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, count
, GMMP_USE_DISPLAY_POINTS
);
1083 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1084 ok(MYERROR
== GetLastError(),
1085 "expected error %d, got %u\n", MYERROR
, GetLastError());
1088 /* test fourth parameter
1089 * a value higher than 64 is expected to fail with ERROR_INVALID_PARAMETER
1091 SetLastError(MYERROR
);
1093 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1094 ok(retval
== count
, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1095 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1096 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1098 SetLastError(MYERROR
);
1100 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1102 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1103 ok(MYERROR
== GetLastError(),
1104 "expected error %d, got %u\n", MYERROR
, GetLastError());
1107 SetLastError(MYERROR
);
1109 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1111 ok((0 <= retval
) && (retval
<= count
), "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1112 ok(MYERROR
== GetLastError(),
1113 "expected error %d, got %u\n", MYERROR
, GetLastError());
1116 SetLastError(MYERROR
);
1117 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1118 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1119 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1120 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1122 /* it was not possible to force an error with the fifth parameter on win2k */
1124 /* test combinations of wrong parameters to see which error wins */
1125 SetLastError(MYERROR
);
1126 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1127 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1128 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1129 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1131 SetLastError(MYERROR
);
1132 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1133 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1134 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1135 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1137 SetLastError(MYERROR
);
1138 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1139 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1140 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1141 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1143 SetLastError(MYERROR
);
1144 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1145 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1146 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1147 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1153 static void test_key_map(void)
1155 HKL kl
= GetKeyboardLayout(0);
1158 static const UINT numpad_collisions
[][2] = {
1159 { VK_NUMPAD0
, VK_INSERT
},
1160 { VK_NUMPAD1
, VK_END
},
1161 { VK_NUMPAD2
, VK_DOWN
},
1162 { VK_NUMPAD3
, VK_NEXT
},
1163 { VK_NUMPAD4
, VK_LEFT
},
1164 { VK_NUMPAD6
, VK_RIGHT
},
1165 { VK_NUMPAD7
, VK_HOME
},
1166 { VK_NUMPAD8
, VK_UP
},
1167 { VK_NUMPAD9
, VK_PRIOR
},
1170 s
= MapVirtualKeyEx(VK_SHIFT
, MAPVK_VK_TO_VSC
, kl
);
1171 ok(s
!= 0, "MapVirtualKeyEx(VK_SHIFT) should return non-zero\n");
1172 sL
= MapVirtualKeyEx(VK_LSHIFT
, MAPVK_VK_TO_VSC
, kl
);
1173 ok(s
== sL
, "%x != %x\n", s
, sL
);
1175 kL
= MapVirtualKeyEx(0x2a, MAPVK_VSC_TO_VK
, kl
);
1176 ok(kL
== VK_SHIFT
, "Scan code -> vKey = %x (not VK_SHIFT)\n", kL
);
1177 kR
= MapVirtualKeyEx(0x36, MAPVK_VSC_TO_VK
, kl
);
1178 ok(kR
== VK_SHIFT
, "Scan code -> vKey = %x (not VK_SHIFT)\n", kR
);
1180 kL
= MapVirtualKeyEx(0x2a, MAPVK_VSC_TO_VK_EX
, kl
);
1181 ok(kL
== VK_LSHIFT
, "Scan code -> vKey = %x (not VK_LSHIFT)\n", kL
);
1182 kR
= MapVirtualKeyEx(0x36, MAPVK_VSC_TO_VK_EX
, kl
);
1183 ok(kR
== VK_RSHIFT
, "Scan code -> vKey = %x (not VK_RSHIFT)\n", kR
);
1185 /* test that MAPVK_VSC_TO_VK prefers the non-numpad vkey if there's ambiguity */
1186 for (i
= 0; i
< sizeof(numpad_collisions
)/sizeof(numpad_collisions
[0]); i
++)
1188 UINT numpad_scan
= MapVirtualKeyEx(numpad_collisions
[i
][0], MAPVK_VK_TO_VSC
, kl
);
1189 UINT other_scan
= MapVirtualKeyEx(numpad_collisions
[i
][1], MAPVK_VK_TO_VSC
, kl
);
1191 /* do they really collide for this layout? */
1192 if (numpad_scan
&& other_scan
== numpad_scan
)
1194 UINT vkey
= MapVirtualKeyEx(numpad_scan
, MAPVK_VSC_TO_VK
, kl
);
1195 ok(vkey
!= numpad_collisions
[i
][0],
1196 "Got numpad vKey %x for scan code %x when there was another choice\n",
1202 static void test_ToUnicode(void)
1206 const BYTE SC_RETURN
= 0x1c, SC_TAB
= 0x0f;
1207 const BYTE HIGHEST_BIT
= 0x80;
1209 for(i
=0; i
<256; i
++)
1212 SetLastError(0xdeadbeef);
1213 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, state
, wStr
, 2, 0);
1214 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1216 skip("ToUnicode is not implemented\n");
1220 ok(ret
== 1, "ToUnicode for Return key didn't return 1 (was %i)\n", ret
);
1222 ok(wStr
[0]=='\r', "ToUnicode for CTRL + Return was %i (expected 13)\n", wStr
[0]);
1223 state
[VK_CONTROL
] |= HIGHEST_BIT
;
1224 state
[VK_LCONTROL
] |= HIGHEST_BIT
;
1226 ret
= ToUnicode(VK_TAB
, SC_TAB
, state
, wStr
, 2, 0);
1227 todo_wine
ok(ret
== 0, "ToUnicode for CTRL + Tab didn't return 0 (was %i)\n", ret
);
1229 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, state
, wStr
, 2, 0);
1230 ok(ret
== 1, "ToUnicode for CTRL + Return didn't return 1 (was %i)\n", ret
);
1232 ok(wStr
[0]=='\n', "ToUnicode for CTRL + Return was %i (expected 10)\n", wStr
[0]);
1234 state
[VK_SHIFT
] |= HIGHEST_BIT
;
1235 state
[VK_LSHIFT
] |= HIGHEST_BIT
;
1236 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, state
, wStr
, 2, 0);
1237 todo_wine
ok(ret
== 0, "ToUnicode for CTRL + SHIFT + Return didn't return 0 (was %i)\n", ret
);
1242 init_function_pointers();
1245 skip("SendInput is not available\n");
1247 test_Input_whitebox();
1249 test_Input_blackbox();
1251 test_mouse_ll_hook();
1255 if(pGetMouseMovePointsEx
)
1256 test_GetMouseMovePointsEx();
1258 skip("GetMouseMovePointsEx is not available\n");