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
47 #define _WIN32_WINNT 0x401
48 #define _WIN32_IE 0x0500
58 #include "wine/test.h"
62 static LONG timetag
= 0x10000000;
67 LONG last_syskey_down
;
73 LONG last_hook_syskey_down
;
74 LONG last_hook_syskey_up
;
76 BOOL sendinput_broken
;
79 static UINT (WINAPI
*pSendInput
) (UINT
, INPUT
*, size_t);
80 static int (WINAPI
*pGetMouseMovePointsEx
) (UINT
, LPMOUSEMOVEPOINT
, LPMOUSEMOVEPOINT
, int, DWORD
);
81 static UINT (WINAPI
*pGetRawInputDeviceList
) (PRAWINPUTDEVICELIST
, PUINT
, UINT
);
83 #define MAXKEYEVENTS 12
84 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
85 and only one message */
87 /* keyboard message names, sorted as their value */
88 static const char *MSGNAME
[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
89 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
91 /* keyevents, add more as needed */
93 { ALTDOWN
= 1, ALTUP
, XDOWN
, XUP
, SHIFTDOWN
, SHIFTUP
, CTRLDOWN
, CTRLUP
} KEV
;
95 static const int GETVKEY
[]={0, VK_MENU
, VK_MENU
, 'X', 'X', VK_SHIFT
, VK_SHIFT
, VK_CONTROL
, VK_CONTROL
};
96 /* matching scan codes */
97 static const int GETSCAN
[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
98 /* matching updown events */
99 static const int GETFLAGS
[]={0, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
};
100 /* matching descriptions */
101 static const char *getdesc
[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
103 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
115 #define ADDTOINPUTS(kev) \
116 inputs[evtctr].type = INPUT_KEYBOARD; \
117 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
118 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
119 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETFLAGS[ kev]; \
120 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
121 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
130 /*******************************************
131 * add new test sets here
132 * the software will make all combinations of the
133 * keyevent defined here
135 static const struct {
137 KEV keydwn
[MAXKEYEVENTS
];
138 KEV keyup
[MAXKEYEVENTS
];
140 { 2, { ALTDOWN
, XDOWN
}, { ALTUP
, XUP
}},
141 { 3, { ALTDOWN
, XDOWN
, SHIFTDOWN
}, { ALTUP
, XUP
, SHIFTUP
}},
142 { 3, { ALTDOWN
, XDOWN
, CTRLDOWN
}, { ALTUP
, XUP
, CTRLUP
}},
143 { 3, { SHIFTDOWN
, XDOWN
, CTRLDOWN
}, { SHIFTUP
, XUP
, CTRLUP
}},
144 { 0 } /* mark the end */
147 /**********************adapted from input.c **********************************/
149 static BYTE InputKeyStateTable
[256];
150 static BYTE AsyncKeyStateTable
[256];
151 static BYTE TrackSysKey
= 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
152 or a WM_KEYUP message */
154 static void init_function_pointers(void)
156 HMODULE hdll
= GetModuleHandleA("user32");
158 #define GET_PROC(func) \
159 p ## func = (void*)GetProcAddress(hdll, #func); \
161 trace("GetProcAddress(%s) failed\n", #func);
164 GET_PROC(GetMouseMovePointsEx
)
165 GET_PROC(GetRawInputDeviceList
)
170 static int KbdMessage( KEV kev
, WPARAM
*pwParam
, LPARAM
*plParam
)
173 int VKey
= GETVKEY
[kev
];
176 flags
= LOBYTE(GETSCAN
[kev
]);
177 if (GETFLAGS
[kev
] & KEYEVENTF_EXTENDEDKEY
) flags
|= KF_EXTENDED
;
179 if (GETFLAGS
[kev
] & KEYEVENTF_KEYUP
)
182 if( (InputKeyStateTable
[VK_MENU
] & 0x80) && (
183 (VKey
== VK_MENU
) || (VKey
== VK_CONTROL
) ||
184 !(InputKeyStateTable
[VK_CONTROL
] & 0x80))) {
185 if( TrackSysKey
== VK_MENU
|| /* <ALT>-down/<ALT>-up sequence */
186 (VKey
!= VK_MENU
)) /* <ALT>-down...<something else>-up */
187 message
= WM_SYSKEYUP
;
190 InputKeyStateTable
[VKey
] &= ~0x80;
191 flags
|= KF_REPEAT
| KF_UP
;
195 if (InputKeyStateTable
[VKey
] & 0x80) flags
|= KF_REPEAT
;
196 if (!(InputKeyStateTable
[VKey
] & 0x80)) InputKeyStateTable
[VKey
] ^= 0x01;
197 InputKeyStateTable
[VKey
] |= 0x80;
198 AsyncKeyStateTable
[VKey
] |= 0x80;
200 message
= WM_KEYDOWN
;
201 if( (InputKeyStateTable
[VK_MENU
] & 0x80) &&
202 !(InputKeyStateTable
[VK_CONTROL
] & 0x80)) {
203 message
= WM_SYSKEYDOWN
;
208 if (InputKeyStateTable
[VK_MENU
] & 0x80) flags
|= KF_ALTDOWN
;
210 if( plParam
) *plParam
= MAKELPARAM( 1, flags
);
211 if( pwParam
) *pwParam
= VKey
;
215 /****************************** end copy input.c ****************************/
218 * . prepare the keyevents for SendInputs
219 * . calculate the "expected" messages
220 * . Send the events to our window
221 * . retrieve the messages from the input queue
224 static BOOL
do_test( HWND hwnd
, int seqnr
, const KEV td
[] )
226 INPUT inputs
[MAXKEYEVENTS
];
227 KMSG expmsg
[MAXKEYEVENTS
];
234 TrackSysKey
=0; /* see input.c */
235 for( i
= 0; i
< MAXKEYEVENTS
; i
++) {
237 strcat(buf
, getdesc
[td
[i
]]);
239 expmsg
[i
].message
= KbdMessage(td
[i
], &(expmsg
[i
].wParam
), &(expmsg
[i
].lParam
));
241 expmsg
[i
].message
= 0;
243 for( kmctr
= 0; kmctr
< MAXKEYEVENTS
&& expmsg
[kmctr
].message
; kmctr
++)
245 ok( evtctr
<= MAXKEYEVENTS
, "evtctr is above MAXKEYEVENTS\n" );
246 if( evtctr
!= pSendInput(evtctr
, &inputs
[0], sizeof(INPUT
)))
247 ok (FALSE
, "SendInput failed to send some events\n");
249 if (winetest_debug
> 1)
250 trace("======== key stroke sequence #%d: %s =============\n",
252 while( PeekMessageA(&msg
,hwnd
,WM_KEYFIRST
,WM_KEYLAST
,PM_REMOVE
) ) {
253 if (winetest_debug
> 1)
254 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i
,
255 MSGNAME
[msg
.message
- WM_KEYFIRST
], msg
.wParam
, msg
.lParam
, msg
.time
);
257 ok( msg
.message
== expmsg
[i
].message
&&
258 msg
.wParam
== expmsg
[i
].wParam
&&
259 msg
.lParam
== expmsg
[i
].lParam
,
260 "%u/%u: wrong message %x/%08lx/%08lx expected %s/%08lx/%08lx\n",
261 seqnr
, i
, msg
.message
, msg
.wParam
, msg
.lParam
,
262 MSGNAME
[(expmsg
[i
]).message
- WM_KEYFIRST
], expmsg
[i
].wParam
, expmsg
[i
].lParam
);
266 if (winetest_debug
> 1)
267 trace("%d messages retrieved\n", i
);
270 skip( "simulated keyboard input doesn't work\n" );
273 ok( i
== kmctr
, "message count is wrong: got %d expected: %d\n", i
, kmctr
);
277 /* test all combinations of the specified key events */
278 static BOOL
TestASet( HWND hWnd
, int nrkev
, const KEV kevdwn
[], const KEV kevup
[] )
282 KEV kbuf
[MAXKEYEVENTS
];
283 assert( nrkev
==2 || nrkev
==3);
284 for(i
=0;i
<MAXKEYEVENTS
;i
++) kbuf
[i
]=0;
285 /* two keys involved gives 4 test cases */
287 for(i
=0;i
<nrkev
;i
++) {
288 for(j
=0;j
<nrkev
;j
++) {
290 kbuf
[1] = kevdwn
[1-i
];
292 kbuf
[3] = kevup
[1-j
];
293 if (!do_test( hWnd
, count
++, kbuf
)) return FALSE
;
297 /* three keys involved gives 36 test cases */
299 for(i
=0;i
<nrkev
;i
++){
300 for(j
=0;j
<nrkev
;j
++){
302 for(k
=0;k
<nrkev
;k
++){
303 if(k
==i
|| k
==j
) continue;
304 for(l
=0;l
<nrkev
;l
++){
305 for(m
=0;m
<nrkev
;m
++){
307 for(n
=0;n
<nrkev
;n
++){
308 if(n
==l
||n
==m
) continue;
315 if (!do_test( hWnd
, count
++, kbuf
)) return FALSE
;
326 /* test each set specified in the global testkeyset array */
327 static void TestSysKeys( HWND hWnd
)
330 for(i
=0; testkeyset
[i
].nrkev
;i
++)
331 if (!TestASet( hWnd
, testkeyset
[i
].nrkev
, testkeyset
[i
].keydwn
, testkeyset
[i
].keyup
)) break;
334 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
337 return DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
340 static void test_Input_whitebox(void)
344 HANDLE hInstance
= GetModuleHandleA( NULL
);
346 wclass
.lpszClassName
= "InputSysKeyTestClass";
347 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
348 wclass
.lpfnWndProc
= WndProc
;
349 wclass
.hInstance
= hInstance
;
350 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
351 wclass
.hCursor
= LoadCursorA( NULL
, (LPCSTR
)IDC_ARROW
);
352 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
353 wclass
.lpszMenuName
= 0;
354 wclass
.cbClsExtra
= 0;
355 wclass
.cbWndExtra
= 0;
356 RegisterClassA( &wclass
);
357 /* create the test window that will receive the keystrokes */
358 hWndTest
= CreateWindowA( wclass
.lpszClassName
, "InputSysKeyTest",
359 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
360 NULL
, NULL
, hInstance
, NULL
);
362 ShowWindow( hWndTest
, SW_SHOW
);
363 SetWindowPos( hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
364 SetForegroundWindow( hWndTest
);
365 UpdateWindow( hWndTest
);
367 /* flush pending messages */
368 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
370 SetFocus( hWndTest
);
371 TestSysKeys( hWndTest
);
372 DestroyWindow(hWndTest
);
375 static inline BOOL
is_keyboard_message( UINT message
)
377 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
380 static inline BOOL
is_mouse_message( UINT message
)
382 return (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
);
385 /* try to make sure pending X events have been processed before continuing */
386 static void empty_message_queue(void)
390 int min_timeout
= 50;
391 DWORD time
= GetTickCount() + diff
;
395 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
396 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
398 if (is_keyboard_message(msg
.message
) || is_mouse_message(msg
.message
))
399 ok(msg
.time
!= 0, "message %#x has time set to 0\n", msg
.message
);
401 TranslateMessage(&msg
);
402 DispatchMessageA(&msg
);
404 diff
= time
- GetTickCount();
408 struct transition_s
{
428 UINT message
; /* the WM_* code */
429 msg_flags_t flags
; /* message props */
430 WPARAM wParam
; /* expected value of wParam */
431 LPARAM lParam
; /* expected value of lParam */
434 static const struct sendinput_test_s
{
438 struct transition_s expected_transitions
[MAXKEYEVENTS
+1];
439 struct message expected_messages
[MAXKEYMESSAGES
+1];
440 } sendinput_test
[] = {
443 {VK_LMENU
, 0, FALSE
, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
444 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_LMENU
}, {WM_SYSKEYDOWN
}, {0}}},
445 {'F', 0, FALSE
, {{'F', 0x00}, {0}},
446 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
},
448 {WM_SYSCOMMAND
}, {0}}},
449 {'F', KEYEVENTF_KEYUP
, FALSE
, {{'F', 0x80}, {0}},
450 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
451 {VK_LMENU
, KEYEVENTF_KEYUP
, FALSE
, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
452 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
456 {VK_LCONTROL
, 0, FALSE
, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
457 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
458 {'O', 0, FALSE
, {{'O', 0x00}, {0}},
459 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
460 {'O', KEYEVENTF_KEYUP
, FALSE
, {{'O', 0x80}, {0}},
461 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
462 {VK_LCONTROL
, KEYEVENTF_KEYUP
, FALSE
, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
463 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
465 /* test ALT+CTRL+X */
467 {VK_LMENU
, 0, FALSE
, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
468 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
}, {0}}},
469 {VK_LCONTROL
, 0, FALSE
, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
470 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
471 {'X', 0, FALSE
, {{'X', 0x00}, {0}},
472 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
473 {'X', KEYEVENTF_KEYUP
, FALSE
, {{'X', 0x80}, {0}},
474 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
475 {VK_LCONTROL
, KEYEVENTF_KEYUP
, FALSE
, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
476 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
477 {VK_LMENU
, KEYEVENTF_KEYUP
, FALSE
, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
478 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
482 {VK_LSHIFT
, 0, FALSE
, {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
483 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
484 {'A', 0, FALSE
, {{'A', 0x00}, {0}},
485 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
486 {'A', KEYEVENTF_KEYUP
, FALSE
, {{'A', 0x80}, {0}},
487 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
488 {VK_LSHIFT
, KEYEVENTF_KEYUP
, FALSE
, {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
489 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
490 /* test L-SHIFT & R-SHIFT: */
491 /* RSHIFT == LSHIFT */
493 {VK_RSHIFT
, 0, FALSE
,
494 /* recent windows versions (>= w2k3) correctly report an RSHIFT transition */
495 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00, TRUE
}, {VK_RSHIFT
, 0x00, TRUE
}, {0}},
496 {{WM_KEYDOWN
, hook
|wparam
, VK_RSHIFT
},
498 {VK_RSHIFT
, KEYEVENTF_KEYUP
, FALSE
,
499 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80, TRUE
}, {VK_RSHIFT
, 0x80, TRUE
}, {0}},
500 {{WM_KEYUP
, hook
, hook
|wparam
, VK_RSHIFT
},
503 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
505 {VK_LSHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
506 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
507 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_EXTENDED
},
508 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
509 {VK_LSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
510 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
511 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
512 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
513 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
515 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
516 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
517 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
518 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
519 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
520 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
521 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
522 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
524 /* Note about wparam for hook with generic key (VK_SHIFT, VK_CONTROL, VK_MENU):
525 win2k - sends to hook whatever we generated here
526 winXP+ - Attempts to convert key to L/R key but not always correct
528 /* SHIFT == LSHIFT */
531 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
532 {{WM_KEYDOWN
, hook
/* |wparam */|lparam
, VK_SHIFT
, 0},
533 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
534 {VK_SHIFT
, KEYEVENTF_KEYUP
, FALSE
,
535 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
536 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_UP
},
537 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
538 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
540 {VK_SHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
541 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
542 {{WM_KEYDOWN
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_EXTENDED
},
543 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
544 {VK_SHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
545 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
546 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
547 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
549 /* test L-CONTROL & R-CONTROL: */
550 /* RCONTROL == LCONTROL */
552 {VK_RCONTROL
, 0, FALSE
,
553 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
554 {{WM_KEYDOWN
, hook
|wparam
, VK_RCONTROL
},
555 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
556 {VK_RCONTROL
, KEYEVENTF_KEYUP
, FALSE
,
557 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
558 {{WM_KEYUP
, hook
|wparam
, VK_RCONTROL
},
559 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
560 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
562 {VK_LCONTROL
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
563 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
564 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_EXTENDED
},
565 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
566 {VK_LCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
567 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
568 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
569 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
570 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
572 {VK_RCONTROL
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
573 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
574 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_EXTENDED
},
575 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
576 {VK_RCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
577 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
578 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
579 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
580 /* CONTROL == LCONTROL */
582 {VK_CONTROL
, 0, FALSE
,
583 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
584 {{WM_KEYDOWN
, hook
/*|wparam, VK_CONTROL*/},
585 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
586 {VK_CONTROL
, KEYEVENTF_KEYUP
, FALSE
,
587 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
588 {{WM_KEYUP
, hook
/*|wparam, VK_CONTROL*/},
589 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
590 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
592 {VK_CONTROL
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
593 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
594 {{WM_KEYDOWN
, hook
/*|wparam*/|lparam
, VK_CONTROL
, LLKHF_EXTENDED
},
595 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
596 {VK_CONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
597 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
598 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_CONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
599 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
601 /* test L-MENU & R-MENU: */
605 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {VK_CONTROL
, 0x00, 1}, {VK_LCONTROL
, 0x01, 1}, {0}},
606 {{WM_SYSKEYDOWN
, hook
|wparam
|optional
, VK_LCONTROL
},
607 {WM_SYSKEYDOWN
, hook
|wparam
, VK_RMENU
},
608 {WM_KEYDOWN
, wparam
|lparam
|optional
, VK_CONTROL
, 0},
609 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
610 {VK_RMENU
, KEYEVENTF_KEYUP
, TRUE
,
611 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {VK_CONTROL
, 0x81, 1}, {VK_LCONTROL
, 0x80, 1}, {0}},
612 {{WM_KEYUP
, hook
|wparam
|optional
, VK_LCONTROL
},
613 {WM_KEYUP
, hook
|wparam
, VK_RMENU
},
614 {WM_SYSKEYUP
, wparam
|lparam
|optional
, VK_CONTROL
, KF_UP
},
615 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
616 {WM_SYSCOMMAND
, optional
}, {0}}},
617 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
619 {VK_LMENU
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
620 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
621 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_EXTENDED
},
622 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
623 {VK_LMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, TRUE
,
624 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
625 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
626 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
627 {WM_SYSCOMMAND
}, {0}}},
628 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
630 {VK_RMENU
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
631 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {VK_CONTROL
, 0x00, 1}, {VK_LCONTROL
, 0x01, 1}, {0}},
632 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
|optional
, VK_LCONTROL
, 0},
633 {WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_EXTENDED
},
634 {WM_KEYDOWN
, wparam
|lparam
|optional
, VK_CONTROL
, 0},
635 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
636 {VK_RMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, TRUE
,
637 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {VK_CONTROL
, 0x81, 1}, {VK_LCONTROL
, 0x80, 1}, {0}},
638 {{WM_KEYUP
, hook
|wparam
|lparam
|optional
, VK_LCONTROL
, LLKHF_UP
},
639 {WM_KEYUP
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
640 {WM_SYSKEYUP
, wparam
|lparam
|optional
, VK_CONTROL
, KF_UP
},
641 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
642 {WM_SYSCOMMAND
, optional
}, {0}}},
646 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
647 {{WM_SYSKEYDOWN
, hook
/*|wparam, VK_MENU*/},
648 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
649 {VK_MENU
, KEYEVENTF_KEYUP
, TRUE
,
650 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
651 {{WM_KEYUP
, hook
/*|wparam, VK_MENU*/},
652 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
653 {WM_SYSCOMMAND
}, {0}}},
654 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
656 {VK_MENU
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
657 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {VK_CONTROL
, 0x00, 1}, {VK_LCONTROL
, 0x01, 1}, {0}},
658 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
|optional
, VK_CONTROL
, 0},
659 {WM_SYSKEYDOWN
, hook
/*|wparam*/|lparam
, VK_MENU
, LLKHF_EXTENDED
},
660 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
661 {VK_MENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, TRUE
,
662 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {VK_CONTROL
, 0x81, 1}, {VK_LCONTROL
, 0x80, 1}, {0}},
663 {{WM_KEYUP
, hook
|wparam
|lparam
|optional
, VK_CONTROL
, LLKHF_UP
},
664 {WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_MENU
, LLKHF_UP
|LLKHF_EXTENDED
},
665 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
666 {WM_SYSCOMMAND
}, {0}}},
668 /* test LSHIFT & RSHIFT */
670 {VK_LSHIFT
, 0, FALSE
,
671 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
672 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, 0},
673 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
674 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
675 {{VK_RSHIFT
, 0x00}, {0}},
676 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
677 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
678 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
679 {{VK_RSHIFT
, 0x80}, {0}},
680 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
681 {WM_KEYUP
, optional
}, {0}}},
682 {VK_LSHIFT
, KEYEVENTF_KEYUP
, FALSE
,
683 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
684 {{WM_KEYUP
, hook
|wparam
, VK_LSHIFT
},
685 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
687 {0, 0, FALSE
, {{0}}, {{0}}} /* end */
690 static struct message sent_messages
[MAXKEYMESSAGES
];
691 static UINT sent_messages_cnt
;
693 /* Verify that only specified key state transitions occur */
694 static void compare_and_check(int id
, BYTE
*ks1
, BYTE
*ks2
,
695 const struct sendinput_test_s
*test
, BOOL foreground
)
697 int i
, failcount
= 0;
698 const struct transition_s
*t
= test
->expected_transitions
;
700 const struct message
*expected
= test
->expected_messages
;
702 while (t
->wVk
&& foreground
) {
703 /* We won't receive any information from GetKeyboardState() if we're
704 * not the foreground window. */
705 BOOL matched
= ((ks1
[t
->wVk
]&0x80) == (t
->before_state
&0x80)
706 && (ks2
[t
->wVk
]&0x80) == (~t
->before_state
&0x80));
708 if (!matched
&& !t
->optional
&& test
->_todo_wine
)
712 ok(matched
, "%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);
718 ok(matched
|| t
->optional
, "%2d (%x/%x): %02x from %02x -> %02x "
719 "instead of %02x -> %02x\n", id
, test
->wVk
, test
->dwFlags
,
720 t
->wVk
, ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
721 ~t
->before_state
&0x80);
723 ks2
[t
->wVk
] = ks1
[t
->wVk
]; /* clear the match */
726 for (i
= 0; i
< 256; i
++)
727 if (ks2
[i
] != ks1
[i
] && test
->_todo_wine
)
731 ok(FALSE
, "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
732 id
, test
->wVk
, test
->dwFlags
, i
, ks1
[i
], ks2
[i
]);
735 ok(ks2
[i
] == ks1
[i
], "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
736 id
, test
->wVk
, test
->dwFlags
, i
, ks1
[i
], ks2
[i
]);
738 while (expected
->message
&& actual_cnt
< sent_messages_cnt
)
740 const struct message
*actual
= &sent_messages
[actual_cnt
];
742 if (expected
->message
== actual
->message
)
744 if (expected
->flags
& wparam
)
746 if ((expected
->flags
& optional
) && (expected
->wParam
!= actual
->wParam
))
751 if (expected
->wParam
!= actual
->wParam
&& test
->_todo_wine
)
755 ok(FALSE
, "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
756 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
759 ok(expected
->wParam
== actual
->wParam
,
760 "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
761 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
763 if (expected
->flags
& lparam
)
765 if (expected
->lParam
!= actual
->lParam
&& test
->_todo_wine
)
769 ok(FALSE
, "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
770 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
773 ok(expected
->lParam
== actual
->lParam
,
774 "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
775 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
777 ok((expected
->flags
& hook
) == (actual
->flags
& hook
),
778 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
779 id
, test
->wVk
, test
->dwFlags
, expected
->message
);
782 else if (expected
->flags
& optional
)
787 else if (!(expected
->flags
& hook
) && !foreground
)
789 /* If we weren't able to receive foreground status, we won't get
790 * any window messages. */
794 /* NT4 doesn't send SYSKEYDOWN/UP to hooks, only KEYDOWN/UP */
795 else if ((expected
->flags
& hook
) &&
796 (expected
->message
== WM_SYSKEYDOWN
|| expected
->message
== WM_SYSKEYUP
) &&
797 (actual
->message
== expected
->message
- 4))
799 ok((expected
->flags
& hook
) == (actual
->flags
& hook
),
800 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
801 id
, test
->wVk
, test
->dwFlags
, expected
->message
);
803 /* For VK_RMENU, at least localized Win2k/XP sends KEYDOWN/UP
804 * instead of SYSKEYDOWN/UP to the WNDPROC */
805 else if (test
->wVk
== VK_RMENU
&& !(expected
->flags
& hook
) &&
806 (expected
->message
== WM_SYSKEYDOWN
|| expected
->message
== WM_SYSKEYUP
) &&
807 (actual
->message
== expected
->message
- 4))
809 ok(expected
->wParam
== actual
->wParam
&& expected
->lParam
== actual
->lParam
,
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
);
813 else if (test
->_todo_wine
)
818 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
819 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
823 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
824 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
829 /* skip all optional trailing messages */
830 while (expected
->message
&& ((expected
->flags
& optional
) || (!(expected
->flags
& hook
) && !foreground
)))
834 if (expected
->message
|| actual_cnt
< sent_messages_cnt
)
836 if (test
->_todo_wine
)
840 ok(FALSE
, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
841 id
, test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
844 ok(FALSE
, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
845 id
, test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
848 if( test
->_todo_wine
&& !failcount
) /* succeeded yet marked todo */
850 ok(TRUE
, "%2d (%x/%x): marked \"todo_wine\" but succeeds\n", id
, test
->wVk
, test
->dwFlags
);
852 sent_messages_cnt
= 0;
855 /* WndProc2 checks that we get at least the messages specified */
856 static LRESULT CALLBACK
WndProc2(HWND hWnd
, UINT Msg
, WPARAM wParam
,
859 if (winetest_debug
> 1) trace("MSG: %8x W:%8lx L:%8lx\n", Msg
, wParam
, lParam
);
861 if ((Msg
>= WM_KEYFIRST
&& Msg
<= WM_KEYLAST
) || Msg
== WM_SYSCOMMAND
)
863 ok(sent_messages_cnt
< MAXKEYMESSAGES
, "Too many messages\n");
864 if (sent_messages_cnt
< MAXKEYMESSAGES
)
866 sent_messages
[sent_messages_cnt
].message
= Msg
;
867 sent_messages
[sent_messages_cnt
].flags
= 0;
868 sent_messages
[sent_messages_cnt
].wParam
= wParam
;
869 sent_messages
[sent_messages_cnt
++].lParam
= HIWORD(lParam
) & (KF_UP
|KF_EXTENDED
);
872 return DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
875 static LRESULT CALLBACK
hook_proc(int code
, WPARAM wparam
, LPARAM lparam
)
877 KBDLLHOOKSTRUCT
*hook_info
= (KBDLLHOOKSTRUCT
*)lparam
;
879 if (code
== HC_ACTION
)
881 ok(sent_messages_cnt
< MAXKEYMESSAGES
, "Too many messages\n");
882 if (sent_messages_cnt
< MAXKEYMESSAGES
)
884 sent_messages
[sent_messages_cnt
].message
= wparam
;
885 sent_messages
[sent_messages_cnt
].flags
= hook
;
886 sent_messages
[sent_messages_cnt
].wParam
= hook_info
->vkCode
;
887 sent_messages
[sent_messages_cnt
++].lParam
= hook_info
->flags
& (LLKHF_UP
|LLKHF_EXTENDED
);
890 if(0) /* For some reason not stable on Wine */
892 if (wparam
== WM_KEYDOWN
|| wparam
== WM_SYSKEYDOWN
)
893 ok(!(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000), "key %x should be up\n", hook_info
->vkCode
);
894 else if (wparam
== WM_KEYUP
|| wparam
== WM_SYSKEYUP
)
895 ok(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000, "key %x should be down\n", hook_info
->vkCode
);
898 if (winetest_debug
> 1)
899 trace("Hook: w=%lx vk:%8x sc:%8x fl:%8x %lx\n", wparam
,
900 hook_info
->vkCode
, hook_info
->scanCode
, hook_info
->flags
, hook_info
->dwExtraInfo
);
902 return CallNextHookEx( 0, code
, wparam
, lparam
);
904 static void test_Input_blackbox(void)
908 BYTE ks1
[256], ks2
[256];
909 LONG_PTR prevWndProc
;
914 if (GetKeyboardLayout(0) != (HKL
)(ULONG_PTR
)0x04090409)
916 skip("Skipping Input_blackbox test on non-US keyboard\n");
919 window
= CreateWindowA("Static", NULL
, WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
920 |WS_VISIBLE
, 0, 0, 200, 60, NULL
, NULL
,
922 ok(window
!= NULL
, "error: %d\n", (int) GetLastError());
923 SetWindowPos( window
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
924 foreground
= SetForegroundWindow( window
);
926 skip("Failed to set foreground window; some tests will be skipped.\n");
928 if (!(hook
= SetWindowsHookExA(WH_KEYBOARD_LL
, hook_proc
, GetModuleHandleA( NULL
), 0)))
930 DestroyWindow(window
);
931 win_skip("WH_KEYBOARD_LL is not supported\n");
935 /* must process all initial messages, otherwise X11DRV_KeymapNotify unsets
936 * key state set by SendInput(). */
937 empty_message_queue();
939 prevWndProc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
) WndProc2
);
940 ok(prevWndProc
!= 0 || GetLastError() == 0, "error: %d\n", (int) GetLastError());
942 i
.type
= INPUT_KEYBOARD
;
944 i
.u
.ki
.dwExtraInfo
= 0;
946 for (ii
= 0; ii
< sizeof(sendinput_test
)/sizeof(struct sendinput_test_s
)-1;
948 GetKeyboardState(ks1
);
949 i
.u
.ki
.wScan
= ii
+1 /* useful for debugging */;
950 i
.u
.ki
.dwFlags
= sendinput_test
[ii
].dwFlags
;
951 i
.u
.ki
.wVk
= sendinput_test
[ii
].wVk
;
952 pSendInput(1, (INPUT
*)&i
, sizeof(TEST_INPUT
));
953 empty_message_queue();
954 GetKeyboardState(ks2
);
955 compare_and_check(ii
, ks1
, ks2
, &sendinput_test
[ii
], foreground
);
958 empty_message_queue();
959 DestroyWindow(window
);
960 UnhookWindowsHookEx(hook
);
963 static void reset_key_status(void)
965 key_status
.last_key_down
= -1;
966 key_status
.last_key_up
= -1;
967 key_status
.last_syskey_down
= -1;
968 key_status
.last_syskey_up
= -1;
969 key_status
.last_char
= -1;
970 key_status
.last_syschar
= -1;
971 key_status
.last_hook_down
= -1;
972 key_status
.last_hook_up
= -1;
973 key_status
.last_hook_syskey_down
= -1;
974 key_status
.last_hook_syskey_up
= -1;
975 key_status
.expect_alt
= FALSE
;
976 key_status
.sendinput_broken
= FALSE
;
979 static void test_unicode_keys(HWND hwnd
, HHOOK hook
)
981 TEST_INPUT inputs
[2];
984 /* init input data that never changes */
985 inputs
[1].type
= inputs
[0].type
= INPUT_KEYBOARD
;
986 inputs
[1].u
.ki
.dwExtraInfo
= inputs
[0].u
.ki
.dwExtraInfo
= 0;
987 inputs
[1].u
.ki
.time
= inputs
[0].u
.ki
.time
= 0;
989 /* pressing & releasing a single unicode character */
990 inputs
[0].u
.ki
.wVk
= 0;
991 inputs
[0].u
.ki
.wScan
= 0x3c0;
992 inputs
[0].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
;
995 pSendInput(1, (INPUT
*)inputs
, sizeof(INPUT
));
996 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
997 if(msg
.message
== WM_KEYDOWN
&& msg
.wParam
== VK_PACKET
){
998 TranslateMessage(&msg
);
1000 DispatchMessageW(&msg
);
1002 if(!key_status
.sendinput_broken
){
1003 ok(key_status
.last_key_down
== VK_PACKET
,
1004 "Last keydown msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_key_down
);
1005 ok(key_status
.last_char
== 0x3c0,
1006 "Last char msg wparam should have been 0x3c0 (was: 0x%x)\n", key_status
.last_char
);
1008 ok(key_status
.last_hook_down
== 0x3c0,
1009 "Last hookdown msg should have been 0x3c0, was: 0x%x\n", key_status
.last_hook_down
);
1012 inputs
[1].u
.ki
.wVk
= 0;
1013 inputs
[1].u
.ki
.wScan
= 0x3c0;
1014 inputs
[1].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
| KEYEVENTF_KEYUP
;
1017 pSendInput(1, (INPUT
*)(inputs
+1), sizeof(INPUT
));
1018 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1019 if(msg
.message
== WM_KEYDOWN
&& msg
.wParam
== VK_PACKET
){
1020 TranslateMessage(&msg
);
1022 DispatchMessageW(&msg
);
1024 if(!key_status
.sendinput_broken
){
1025 ok(key_status
.last_key_up
== VK_PACKET
,
1026 "Last keyup msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_key_up
);
1028 ok(key_status
.last_hook_up
== 0x3c0,
1029 "Last hookup msg should have been 0x3c0, was: 0x%x\n", key_status
.last_hook_up
);
1032 /* holding alt, pressing & releasing a unicode character, releasing alt */
1033 inputs
[0].u
.ki
.wVk
= VK_LMENU
;
1034 inputs
[0].u
.ki
.wScan
= 0;
1035 inputs
[0].u
.ki
.dwFlags
= 0;
1037 inputs
[1].u
.ki
.wVk
= 0;
1038 inputs
[1].u
.ki
.wScan
= 0x3041;
1039 inputs
[1].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
;
1042 key_status
.expect_alt
= TRUE
;
1043 pSendInput(2, (INPUT
*)inputs
, sizeof(INPUT
));
1044 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1045 if(msg
.message
== WM_SYSKEYDOWN
&& msg
.wParam
== VK_PACKET
){
1046 TranslateMessage(&msg
);
1048 DispatchMessageW(&msg
);
1050 if(!key_status
.sendinput_broken
){
1051 ok(key_status
.last_syskey_down
== VK_PACKET
,
1052 "Last syskeydown msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_syskey_down
);
1053 ok(key_status
.last_syschar
== 0x3041,
1054 "Last syschar msg should have been 0x3041 (was: 0x%x)\n", key_status
.last_syschar
);
1056 ok(key_status
.last_hook_syskey_down
== 0x3041,
1057 "Last hooksysdown msg should have been 0x3041, was: 0x%x\n", key_status
.last_hook_syskey_down
);
1060 inputs
[1].u
.ki
.wVk
= 0;
1061 inputs
[1].u
.ki
.wScan
= 0x3041;
1062 inputs
[1].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
| KEYEVENTF_KEYUP
;
1064 inputs
[0].u
.ki
.wVk
= VK_LMENU
;
1065 inputs
[0].u
.ki
.wScan
= 0;
1066 inputs
[0].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
1069 key_status
.expect_alt
= TRUE
;
1070 pSendInput(2, (INPUT
*)inputs
, sizeof(INPUT
));
1071 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1072 if(msg
.message
== WM_SYSKEYDOWN
&& msg
.wParam
== VK_PACKET
){
1073 TranslateMessage(&msg
);
1075 DispatchMessageW(&msg
);
1077 if(!key_status
.sendinput_broken
){
1078 ok(key_status
.last_key_up
== VK_PACKET
,
1079 "Last keyup msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_key_up
);
1081 ok(key_status
.last_hook_up
== 0x3041,
1082 "Last hook up msg should have been 0x3041, was: 0x%x\n", key_status
.last_hook_up
);
1086 static LRESULT CALLBACK
unicode_wnd_proc( HWND hWnd
, UINT msg
, WPARAM wParam
,
1091 key_status
.last_key_down
= wParam
;
1094 key_status
.last_syskey_down
= wParam
;
1097 key_status
.last_key_up
= wParam
;
1100 key_status
.last_syskey_up
= wParam
;
1103 key_status
.last_char
= wParam
;
1106 key_status
.last_syschar
= wParam
;
1109 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1112 static LRESULT CALLBACK
llkbd_unicode_hook(int nCode
, WPARAM wParam
, LPARAM lParam
)
1114 if(nCode
== HC_ACTION
){
1115 LPKBDLLHOOKSTRUCT info
= (LPKBDLLHOOKSTRUCT
)lParam
;
1117 key_status
.sendinput_broken
= TRUE
;
1118 win_skip("SendInput doesn't support unicode on this platform\n");
1120 if(key_status
.expect_alt
){
1121 ok(info
->vkCode
== VK_LMENU
, "vkCode should have been VK_LMENU[0x%04x], was: 0x%x\n", VK_LMENU
, info
->vkCode
);
1122 key_status
.expect_alt
= FALSE
;
1124 ok(info
->vkCode
== VK_PACKET
, "vkCode should have been VK_PACKET[0x%04x], was: 0x%x\n", VK_PACKET
, info
->vkCode
);
1128 key_status
.last_hook_down
= info
->scanCode
;
1131 key_status
.last_hook_up
= info
->scanCode
;
1134 key_status
.last_hook_syskey_down
= info
->scanCode
;
1137 key_status
.last_hook_syskey_up
= info
->scanCode
;
1141 return CallNextHookEx(NULL
, nCode
, wParam
, lParam
);
1144 static void test_Input_unicode(void)
1146 WCHAR classNameW
[] = {'I','n','p','u','t','U','n','i','c','o','d','e',
1147 'K','e','y','T','e','s','t','C','l','a','s','s',0};
1148 WCHAR windowNameW
[] = {'I','n','p','u','t','U','n','i','c','o','d','e',
1149 'K','e','y','T','e','s','t',0};
1152 HANDLE hInstance
= GetModuleHandleW(NULL
);
1154 HMODULE hModuleImm32
;
1155 BOOL (WINAPI
*pImmDisableIME
)(DWORD
);
1157 wclass
.lpszClassName
= classNameW
;
1158 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
1159 wclass
.lpfnWndProc
= unicode_wnd_proc
;
1160 wclass
.hInstance
= hInstance
;
1161 wclass
.hIcon
= LoadIconW(0, (LPCWSTR
)IDI_APPLICATION
);
1162 wclass
.hCursor
= LoadCursorW( NULL
, (LPCWSTR
)IDC_ARROW
);
1163 wclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1164 wclass
.lpszMenuName
= 0;
1165 wclass
.cbClsExtra
= 0;
1166 wclass
.cbWndExtra
= 0;
1167 if(!RegisterClassW(&wclass
)){
1168 win_skip("Unicode functions not supported\n");
1172 hModuleImm32
= LoadLibraryA("imm32.dll");
1174 pImmDisableIME
= (void *)GetProcAddress(hModuleImm32
, "ImmDisableIME");
1178 pImmDisableIME
= NULL
;
1179 FreeLibrary(hModuleImm32
);
1181 /* create the test window that will receive the keystrokes */
1182 hWndTest
= CreateWindowW(wclass
.lpszClassName
, windowNameW
,
1183 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
1184 NULL
, NULL
, hInstance
, NULL
);
1187 assert(IsWindowUnicode(hWndTest
));
1189 hook
= SetWindowsHookExW(WH_KEYBOARD_LL
, llkbd_unicode_hook
, GetModuleHandleW(NULL
), 0);
1191 win_skip("unable to set WH_KEYBOARD_LL hook\n");
1193 ShowWindow(hWndTest
, SW_SHOW
);
1194 SetWindowPos(hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1195 SetForegroundWindow(hWndTest
);
1196 UpdateWindow(hWndTest
);
1198 /* flush pending messages */
1199 while (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW(&msg
);
1203 test_unicode_keys(hWndTest
, hook
);
1206 UnhookWindowsHookEx(hook
);
1207 DestroyWindow(hWndTest
);
1210 static void test_keynames(void)
1215 for (i
= 0; i
< 512; i
++)
1217 strcpy(buff
, "----");
1218 len
= GetKeyNameTextA(i
<< 16, buff
, sizeof(buff
));
1219 ok(len
|| !buff
[0], "%d: Buffer is not zeroed\n", i
);
1223 static POINT pt_old
, pt_new
;
1224 static BOOL clipped
;
1227 static LRESULT CALLBACK
hook_proc1( int code
, WPARAM wparam
, LPARAM lparam
)
1229 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
1232 if (code
== HC_ACTION
)
1234 /* This is our new cursor position */
1236 /* Should return previous position */
1238 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
1240 /* Should set new position until hook chain is finished. */
1241 pt
.x
= pt_old
.x
+ STEP
;
1242 pt
.y
= pt_old
.y
+ STEP
;
1243 SetCursorPos(pt
.x
, pt
.y
);
1246 ok(pt1
.x
== pt_old
.x
&& pt1
.y
== pt_old
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
1248 ok(pt1
.x
== pt
.x
&& pt1
.y
== pt
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
1250 return CallNextHookEx( 0, code
, wparam
, lparam
);
1253 static LRESULT CALLBACK
hook_proc2( int code
, WPARAM wparam
, LPARAM lparam
)
1255 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
1258 if (code
== HC_ACTION
)
1260 ok(hook
->pt
.x
== pt_new
.x
&& hook
->pt
.y
== pt_new
.y
,
1261 "Wrong hook coords: (%d %d) != (%d,%d)\n", hook
->pt
.x
, hook
->pt
.y
, pt_new
.x
, pt_new
.y
);
1263 /* Should match position set above */
1266 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
1268 ok(pt
.x
== pt_old
.x
+STEP
&& pt
.y
== pt_old
.y
+STEP
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
1270 return CallNextHookEx( 0, code
, wparam
, lparam
);
1273 static void test_mouse_ll_hook(void)
1280 GetCursorPos(&pt_org
);
1281 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
1282 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
1283 SetCursorPos(100, 100);
1285 if (!(hook2
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc2
, GetModuleHandleA(0), 0)))
1287 win_skip( "cannot set MOUSE_LL hook\n" );
1290 hook1
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc1
, GetModuleHandleA(0), 0);
1292 GetCursorPos(&pt_old
);
1293 mouse_event(MOUSEEVENTF_MOVE
, -STEP
, 0, 0, 0);
1294 GetCursorPos(&pt_old
);
1295 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
);
1296 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, 0, 0, 0);
1297 GetCursorPos(&pt_old
);
1298 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
);
1299 mouse_event(MOUSEEVENTF_MOVE
, 0, -STEP
, 0, 0);
1300 GetCursorPos(&pt_old
);
1301 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
);
1302 mouse_event(MOUSEEVENTF_MOVE
, 0, +STEP
, 0, 0);
1303 GetCursorPos(&pt_old
);
1304 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
);
1306 SetRect(&rc
, 50, 50, 151, 151);
1310 SetCursorPos(40, 40);
1311 GetCursorPos(&pt_old
);
1312 ok(pt_old
.x
== 50 && pt_old
.y
== 50, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
1313 SetCursorPos(160, 160);
1314 GetCursorPos(&pt_old
);
1315 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
1316 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, +STEP
, 0, 0);
1317 GetCursorPos(&pt_old
);
1318 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
1321 pt_new
.x
= pt_new
.y
= 150;
1323 UnhookWindowsHookEx(hook1
);
1325 /* Now check that mouse buttons do not change mouse position
1326 if we don't have MOUSEEVENTF_MOVE flag specified. */
1328 /* We reusing the same hook callback, so make it happy */
1329 pt_old
.x
= pt_new
.x
- STEP
;
1330 pt_old
.y
= pt_new
.y
- STEP
;
1331 mouse_event(MOUSEEVENTF_LEFTUP
, 123, 456, 0, 0);
1333 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1334 mouse_event(MOUSEEVENTF_RIGHTUP
, 456, 123, 0, 0);
1336 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1338 mouse_event(MOUSEEVENTF_LEFTUP
| MOUSEEVENTF_ABSOLUTE
, 123, 456, 0, 0);
1340 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1341 mouse_event(MOUSEEVENTF_RIGHTUP
| MOUSEEVENTF_ABSOLUTE
, 456, 123, 0, 0);
1343 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1345 UnhookWindowsHookEx(hook2
);
1347 DestroyWindow(hwnd
);
1348 SetCursorPos(pt_org
.x
, pt_org
.y
);
1351 static void test_GetMouseMovePointsEx(void)
1354 #define MYERROR 0xdeadbeef
1357 MOUSEMOVEPOINT out
[200];
1360 /* Get a valid content for the input struct */
1361 if(!GetCursorPos(&point
)) {
1362 win_skip("GetCursorPos() failed with error %u\n", GetLastError());
1365 memset(&in
, 0, sizeof(MOUSEMOVEPOINT
));
1369 /* test first parameter
1370 * everything different than sizeof(MOUSEMOVEPOINT)
1371 * is expected to fail with ERROR_INVALID_PARAMETER
1373 SetLastError(MYERROR
);
1374 retval
= pGetMouseMovePointsEx(0, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1375 if (retval
== ERROR_INVALID_PARAMETER
)
1377 win_skip( "GetMouseMovePointsEx broken on WinME\n" );
1380 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1381 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1382 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1384 SetLastError(MYERROR
);
1385 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1386 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1387 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1388 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1390 SetLastError(MYERROR
);
1391 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)+1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1392 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1393 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1394 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1396 /* test second and third parameter
1398 SetLastError(MYERROR
);
1399 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1400 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1401 ok(GetLastError() == ERROR_NOACCESS
|| GetLastError() == MYERROR
,
1402 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1404 SetLastError(MYERROR
);
1405 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1406 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1407 ok(ERROR_NOACCESS
== GetLastError(),
1408 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1410 SetLastError(MYERROR
);
1411 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1412 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1413 ok(ERROR_NOACCESS
== GetLastError(),
1414 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1416 SetLastError(MYERROR
);
1418 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, count
, GMMP_USE_DISPLAY_POINTS
);
1420 ok(GetLastError() == ERROR_POINT_NOT_FOUND
, "unexpected error %u\n", GetLastError());
1422 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1424 /* test fourth parameter
1425 * a value higher than 64 is expected to fail with ERROR_INVALID_PARAMETER
1427 SetLastError(MYERROR
);
1429 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1430 ok(retval
== count
, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1431 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1432 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1434 SetLastError(MYERROR
);
1436 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1438 ok(GetLastError() == ERROR_POINT_NOT_FOUND
, "unexpected error %u\n", GetLastError());
1440 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1442 SetLastError(MYERROR
);
1444 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1446 ok(GetLastError() == ERROR_POINT_NOT_FOUND
, "unexpected error %u\n", GetLastError());
1448 ok((0 <= retval
) && (retval
<= count
), "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1450 SetLastError(MYERROR
);
1451 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1452 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1453 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1454 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1456 /* it was not possible to force an error with the fifth parameter on win2k */
1458 /* test combinations of wrong parameters to see which error wins */
1459 SetLastError(MYERROR
);
1460 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1461 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1462 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1463 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1465 SetLastError(MYERROR
);
1466 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1467 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1468 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1469 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1471 SetLastError(MYERROR
);
1472 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1473 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1474 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1475 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1477 SetLastError(MYERROR
);
1478 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1479 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1480 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1481 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1487 static void test_GetRawInputDeviceList(void)
1489 RAWINPUTDEVICELIST devices
[32];
1490 UINT ret
, oret
, devcount
, odevcount
;
1493 SetLastError(0xdeadbeef);
1494 ret
= pGetRawInputDeviceList(NULL
, NULL
, 0);
1495 err
= GetLastError();
1496 ok(ret
== -1, "expected -1, got %d\n", ret
);
1497 ok(err
== ERROR_INVALID_PARAMETER
, "expected 87, got %d\n", err
);
1499 SetLastError(0xdeadbeef);
1500 ret
= pGetRawInputDeviceList(NULL
, NULL
, sizeof(devices
[0]));
1501 err
= GetLastError();
1502 ok(ret
== -1, "expected -1, got %d\n", ret
);
1503 ok(err
== ERROR_NOACCESS
, "expected 998, got %d\n", err
);
1506 ret
= pGetRawInputDeviceList(NULL
, &devcount
, sizeof(devices
[0]));
1507 ok(ret
== 0, "expected 0, got %d\n", ret
);
1508 ok(devcount
> 0, "expected non-zero\n");
1510 SetLastError(0xdeadbeef);
1512 ret
= pGetRawInputDeviceList(devices
, &devcount
, sizeof(devices
[0]));
1513 err
= GetLastError();
1514 ok(ret
== -1, "expected -1, got %d\n", ret
);
1515 ok(err
== ERROR_INSUFFICIENT_BUFFER
, "expected 122, got %d\n", err
);
1516 ok(devcount
> 0, "expected non-zero\n");
1518 /* devcount contains now the correct number of devices */
1519 ret
= pGetRawInputDeviceList(devices
, &devcount
, sizeof(devices
[0]));
1520 ok(ret
> 0, "expected non-zero\n");
1522 /* check if variable changes from larger to smaller value */
1523 devcount
= odevcount
= sizeof(devices
) / sizeof(devices
[0]);
1524 oret
= ret
= pGetRawInputDeviceList(devices
, &odevcount
, sizeof(devices
[0]));
1525 ok(ret
> 0, "expected non-zero\n");
1526 ok(devcount
== odevcount
, "expected %d, got %d\n", devcount
, odevcount
);
1527 devcount
= odevcount
;
1528 odevcount
= sizeof(devices
) / sizeof(devices
[0]);
1529 ret
= pGetRawInputDeviceList(NULL
, &odevcount
, sizeof(devices
[0]));
1530 ok(ret
== 0, "expected 0, got %d\n", ret
);
1531 ok(odevcount
== oret
, "expected %d, got %d\n", oret
, odevcount
);
1534 static void test_key_map(void)
1536 HKL kl
= GetKeyboardLayout(0);
1539 static const UINT numpad_collisions
[][2] = {
1540 { VK_NUMPAD0
, VK_INSERT
},
1541 { VK_NUMPAD1
, VK_END
},
1542 { VK_NUMPAD2
, VK_DOWN
},
1543 { VK_NUMPAD3
, VK_NEXT
},
1544 { VK_NUMPAD4
, VK_LEFT
},
1545 { VK_NUMPAD6
, VK_RIGHT
},
1546 { VK_NUMPAD7
, VK_HOME
},
1547 { VK_NUMPAD8
, VK_UP
},
1548 { VK_NUMPAD9
, VK_PRIOR
},
1551 s
= MapVirtualKeyExA(VK_SHIFT
, MAPVK_VK_TO_VSC
, kl
);
1552 ok(s
!= 0, "MapVirtualKeyEx(VK_SHIFT) should return non-zero\n");
1553 sL
= MapVirtualKeyExA(VK_LSHIFT
, MAPVK_VK_TO_VSC
, kl
);
1554 ok(s
== sL
|| broken(sL
== 0), /* win9x */
1555 "%x != %x\n", s
, sL
);
1557 kL
= MapVirtualKeyExA(0x2a, MAPVK_VSC_TO_VK
, kl
);
1558 ok(kL
== VK_SHIFT
, "Scan code -> vKey = %x (not VK_SHIFT)\n", kL
);
1559 kR
= MapVirtualKeyExA(0x36, MAPVK_VSC_TO_VK
, kl
);
1560 ok(kR
== VK_SHIFT
, "Scan code -> vKey = %x (not VK_SHIFT)\n", kR
);
1562 kL
= MapVirtualKeyExA(0x2a, MAPVK_VSC_TO_VK_EX
, kl
);
1563 ok(kL
== VK_LSHIFT
|| broken(kL
== 0), /* win9x */
1564 "Scan code -> vKey = %x (not VK_LSHIFT)\n", kL
);
1565 kR
= MapVirtualKeyExA(0x36, MAPVK_VSC_TO_VK_EX
, kl
);
1566 ok(kR
== VK_RSHIFT
|| broken(kR
== 0), /* win9x */
1567 "Scan code -> vKey = %x (not VK_RSHIFT)\n", kR
);
1569 /* test that MAPVK_VSC_TO_VK prefers the non-numpad vkey if there's ambiguity */
1570 for (i
= 0; i
< sizeof(numpad_collisions
)/sizeof(numpad_collisions
[0]); i
++)
1572 UINT numpad_scan
= MapVirtualKeyExA(numpad_collisions
[i
][0], MAPVK_VK_TO_VSC
, kl
);
1573 UINT other_scan
= MapVirtualKeyExA(numpad_collisions
[i
][1], MAPVK_VK_TO_VSC
, kl
);
1575 /* do they really collide for this layout? */
1576 if (numpad_scan
&& other_scan
== numpad_scan
)
1578 UINT vkey
= MapVirtualKeyExA(numpad_scan
, MAPVK_VSC_TO_VK
, kl
);
1579 ok(vkey
!= numpad_collisions
[i
][0],
1580 "Got numpad vKey %x for scan code %x when there was another choice\n",
1589 static const struct tounicode_tests
1593 WCHAR chr
; /* if vk is 0, lookup vk using this char */
1595 WCHAR expect_buf
[4];
1598 { 'A', 0, 0, 1, {'a',0}},
1599 { 'A', ctrl
, 0, 1, {1, 0}},
1600 { 'A', shift
|ctrl
, 0, 1, {1, 0}},
1601 { VK_TAB
, ctrl
, 0, 0, {}},
1602 { VK_TAB
, shift
|ctrl
, 0, 0, {}},
1603 { VK_RETURN
, ctrl
, 0, 1, {'\n', 0}},
1604 { VK_RETURN
, shift
|ctrl
, 0, 0, {}},
1605 { '4', ctrl
, 0, 0, {}},
1606 { '4', shift
|ctrl
, 0, 0, {}},
1607 { 0, ctrl
, '!', 0, {}},
1608 { 0, ctrl
, '\"', 0, {}},
1609 { 0, ctrl
, '#', 0, {}},
1610 { 0, ctrl
, '$', 0, {}},
1611 { 0, ctrl
, '%', 0, {}},
1612 { 0, ctrl
, '\'', 0, {}},
1613 { 0, ctrl
, '(', 0, {}},
1614 { 0, ctrl
, ')', 0, {}},
1615 { 0, ctrl
, '*', 0, {}},
1616 { 0, ctrl
, '+', 0, {}},
1617 { 0, ctrl
, ',', 0, {}},
1618 { 0, ctrl
, '-', 0, {}},
1619 { 0, ctrl
, '.', 0, {}},
1620 { 0, ctrl
, '/', 0, {}},
1621 { 0, ctrl
, ':', 0, {}},
1622 { 0, ctrl
, ';', 0, {}},
1623 { 0, ctrl
, '<', 0, {}},
1624 { 0, ctrl
, '=', 0, {}},
1625 { 0, ctrl
, '>', 0, {}},
1626 { 0, ctrl
, '?', 0, {}},
1627 { 0, ctrl
, '@', 1, {0}},
1628 { 0, ctrl
, '[', 1, {0x1b}},
1629 { 0, ctrl
, '\\', 1, {0x1c}},
1630 { 0, ctrl
, ']', 1, {0x1d}},
1631 { 0, ctrl
, '^', 1, {0x1e}},
1632 { 0, ctrl
, '_', 1, {0x1f}},
1633 { 0, ctrl
, '`', 0, {}},
1634 { VK_SPACE
, 0, 0, 1, {' ',0}},
1635 { VK_SPACE
, shift
, 0, 1, {' ',0}},
1636 { VK_SPACE
, ctrl
, 0, 1, {' ',0}},
1639 static void test_ToUnicode(void)
1643 const BYTE SC_RETURN
= 0x1c, SC_TAB
= 0x0f, SC_A
= 0x1e;
1644 const BYTE HIGHEST_BIT
= 0x80;
1646 BOOL us_kbd
= (GetKeyboardLayout(0) == (HKL
)(ULONG_PTR
)0x04090409);
1648 for(i
=0; i
<256; i
++)
1652 SetLastError(0xdeadbeef);
1653 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, state
, wStr
, 4, 0);
1654 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1656 win_skip("ToUnicode is not implemented\n");
1660 ok(ret
== 1, "ToUnicode for Return key didn't return 1 (was %i)\n", ret
);
1663 ok(wStr
[0]=='\r', "ToUnicode for CTRL + Return was %i (expected 13)\n", wStr
[0]);
1664 ok(wStr
[1]==0 || broken(wStr
[1]!=0) /* nt4 */,
1665 "ToUnicode didn't null-terminate the buffer when there was room.\n");
1668 for (i
= 0; i
< sizeof(utests
) / sizeof(utests
[0]); i
++)
1670 UINT vk
= utests
[i
].vk
, mod
= utests
[i
].modifiers
, scan
;
1676 if (!us_kbd
) continue;
1677 vk_ret
= VkKeyScanW(utests
[i
].chr
);
1678 if (vk_ret
== -1) continue;
1680 if (vk_ret
& 0x100) mod
|= shift
;
1681 if (vk_ret
& 0x200) mod
|= ctrl
;
1683 scan
= MapVirtualKeyW(vk
, MAPVK_VK_TO_VSC
);
1685 state
[VK_SHIFT
] = state
[VK_LSHIFT
] = (mod
& shift
) ? HIGHEST_BIT
: 0;
1686 state
[VK_CONTROL
] = state
[VK_LCONTROL
] = (mod
& ctrl
) ? HIGHEST_BIT
: 0;
1688 ret
= ToUnicode(vk
, scan
, state
, wStr
, 4, 0);
1689 ok(ret
== utests
[i
].expect_ret
, "%d: got %d expected %d\n", i
, ret
, utests
[i
].expect_ret
);
1691 ok(!lstrcmpW(wStr
, utests
[i
].expect_buf
), "%d: got %s expected %s\n", i
, wine_dbgstr_w(wStr
),
1692 wine_dbgstr_w(utests
[i
].expect_buf
));
1695 state
[VK_SHIFT
] = state
[VK_LSHIFT
] = 0;
1696 state
[VK_CONTROL
] = state
[VK_LCONTROL
] = 0;
1698 ret
= ToUnicode(VK_TAB
, SC_TAB
, NULL
, wStr
, 4, 0);
1699 ok(ret
== 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret
);
1700 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, NULL
, wStr
, 4, 0);
1701 ok(ret
== 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret
);
1702 ret
= ToUnicode('A', SC_A
, NULL
, wStr
, 4, 0);
1703 ok(ret
== 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret
);
1704 ret
= ToUnicodeEx(VK_TAB
, SC_TAB
, NULL
, wStr
, 4, 0, GetKeyboardLayout(0));
1705 ok(ret
== 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret
);
1706 ret
= ToUnicodeEx(VK_RETURN
, SC_RETURN
, NULL
, wStr
, 4, 0, GetKeyboardLayout(0));
1707 ok(ret
== 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret
);
1708 ret
= ToUnicodeEx('A', SC_A
, NULL
, wStr
, 4, 0, GetKeyboardLayout(0));
1709 ok(ret
== 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret
);
1712 static void test_ToAscii(void)
1716 const BYTE SC_RETURN
= 0x1c, SC_A
= 0x1e;
1717 const BYTE HIGHEST_BIT
= 0x80;
1720 memset(state
, 0, sizeof(state
));
1723 ret
= ToAscii(VK_RETURN
, SC_RETURN
, state
, &character
, 0);
1724 ok(ret
== 1, "ToAscii for Return key didn't return 1 (was %i)\n", ret
);
1725 ok(character
== '\r', "ToAscii for Return was %i (expected 13)\n", character
);
1728 ret
= ToAscii('A', SC_A
, state
, &character
, 0);
1729 ok(ret
== 1, "ToAscii for character 'A' didn't return 1 (was %i)\n", ret
);
1730 ok(character
== 'a', "ToAscii for character 'A' was %i (expected %i)\n", character
, 'a');
1732 state
[VK_CONTROL
] |= HIGHEST_BIT
;
1733 state
[VK_LCONTROL
] |= HIGHEST_BIT
;
1735 ret
= ToAscii(VK_RETURN
, SC_RETURN
, state
, &character
, 0);
1736 ok(ret
== 1, "ToAscii for CTRL + Return key didn't return 1 (was %i)\n", ret
);
1737 ok(character
== '\n', "ToAscii for CTRL + Return was %i (expected 10)\n", character
);
1740 ret
= ToAscii('A', SC_A
, state
, &character
, 0);
1741 ok(ret
== 1, "ToAscii for CTRL + character 'A' didn't return 1 (was %i)\n", ret
);
1742 ok(character
== 1, "ToAscii for CTRL + character 'A' was %i (expected 1)\n", character
);
1744 state
[VK_SHIFT
] |= HIGHEST_BIT
;
1745 state
[VK_LSHIFT
] |= HIGHEST_BIT
;
1746 ret
= ToAscii(VK_RETURN
, SC_RETURN
, state
, &character
, 0);
1747 ok(ret
== 0, "ToAscii for CTRL + Shift + Return key didn't return 0 (was %i)\n", ret
);
1749 ret
= ToAscii(VK_RETURN
, SC_RETURN
, NULL
, &character
, 0);
1750 ok(ret
== 0, "ToAscii for NULL keystate didn't return 0 (was %i)\n", ret
);
1751 ret
= ToAscii('A', SC_A
, NULL
, &character
, 0);
1752 ok(ret
== 0, "ToAscii for NULL keystate didn't return 0 (was %i)\n", ret
);
1753 ret
= ToAsciiEx(VK_RETURN
, SC_RETURN
, NULL
, &character
, 0, GetKeyboardLayout(0));
1754 ok(ret
== 0, "ToAsciiEx for NULL keystate didn't return 0 (was %i)\n", ret
);
1755 ret
= ToAsciiEx('A', SC_A
, NULL
, &character
, 0, GetKeyboardLayout(0));
1756 ok(ret
== 0, "ToAsciiEx for NULL keystate didn't return 0 (was %i)\n", ret
);
1759 static void test_get_async_key_state(void)
1761 /* input value sanity checks */
1762 ok(0 == GetAsyncKeyState(1000000), "GetAsyncKeyState did not return 0\n");
1763 ok(0 == GetAsyncKeyState(-1000000), "GetAsyncKeyState did not return 0\n");
1766 static void test_keyboard_layout_name(void)
1769 char klid
[KL_NAMELENGTH
];
1771 if (0) /* crashes on native system */
1772 ret
= GetKeyboardLayoutNameA(NULL
);
1774 SetLastError(0xdeadbeef);
1775 ret
= GetKeyboardLayoutNameW(NULL
);
1776 ok(!ret
, "got %d\n", ret
);
1777 ok(GetLastError() == ERROR_NOACCESS
, "got %d\n", GetLastError());
1779 if (GetKeyboardLayout(0) != (HKL
)(ULONG_PTR
)0x04090409) return;
1782 ret
= GetKeyboardLayoutNameA(klid
);
1783 ok(ret
, "GetKeyboardLayoutNameA failed %u\n", GetLastError());
1784 ok(!strcmp(klid
, "00000409"), "expected 00000409, got %s\n", klid
);
1787 static void test_key_names(void)
1792 LONG lparam
= 0x1d << 16;
1794 memset( buffer
, 0xcc, sizeof(buffer
) );
1795 ret
= GetKeyNameTextA( lparam
, buffer
, sizeof(buffer
) );
1796 ok( ret
> 0, "wrong len %u for '%s'\n", ret
, buffer
);
1797 ok( ret
== strlen(buffer
), "wrong len %u for '%s'\n", ret
, buffer
);
1799 memset( buffer
, 0xcc, sizeof(buffer
) );
1801 ret
= GetKeyNameTextA( lparam
, buffer
, prev
);
1802 ok( ret
== prev
- 1, "wrong len %u for '%s'\n", ret
, buffer
);
1803 ok( ret
== strlen(buffer
), "wrong len %u for '%s'\n", ret
, buffer
);
1805 memset( buffer
, 0xcc, sizeof(buffer
) );
1806 ret
= GetKeyNameTextA( lparam
, buffer
, 0 );
1807 ok( ret
== 0, "wrong len %u for '%s'\n", ret
, buffer
);
1808 ok( buffer
[0] == 0, "wrong string '%s'\n", buffer
);
1810 memset( bufferW
, 0xcc, sizeof(bufferW
) );
1811 ret
= GetKeyNameTextW( lparam
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
1812 ok( ret
> 0, "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1813 ok( ret
== lstrlenW(bufferW
), "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1815 memset( bufferW
, 0xcc, sizeof(bufferW
) );
1817 ret
= GetKeyNameTextW( lparam
, bufferW
, prev
);
1818 ok( ret
== prev
- 1, "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1819 ok( ret
== lstrlenW(bufferW
), "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1821 memset( bufferW
, 0xcc, sizeof(bufferW
) );
1822 ret
= GetKeyNameTextW( lparam
, bufferW
, 0 );
1823 ok( ret
== 0, "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1824 ok( bufferW
[0] == 0xcccc, "wrong string %s\n", wine_dbgstr_w(bufferW
) );
1827 static void simulate_click(BOOL left
, int x
, int y
)
1833 memset(input
, 0, sizeof(input
));
1834 input
[0].type
= INPUT_MOUSE
;
1835 U(input
[0]).mi
.dx
= x
;
1836 U(input
[0]).mi
.dy
= y
;
1837 U(input
[0]).mi
.dwFlags
= left
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_RIGHTDOWN
;
1838 input
[1].type
= INPUT_MOUSE
;
1839 U(input
[1]).mi
.dx
= x
;
1840 U(input
[1]).mi
.dy
= y
;
1841 U(input
[1]).mi
.dwFlags
= left
? MOUSEEVENTF_LEFTUP
: MOUSEEVENTF_RIGHTUP
;
1842 events_no
= SendInput(2, input
, sizeof(input
[0]));
1843 ok(events_no
== 2, "SendInput returned %d\n", events_no
);
1846 static BOOL
wait_for_message( MSG
*msg
)
1852 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
1855 if (msg
->message
== WM_PAINT
) DispatchMessageA(msg
);
1858 else if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
1860 if (!ret
) msg
->message
= 0;
1864 static BOOL
wait_for_event(HANDLE event
, int timeout
)
1866 DWORD end_time
= GetTickCount() + timeout
;
1870 if(MsgWaitForMultipleObjects(1, &event
, FALSE
, timeout
, QS_ALLINPUT
) == WAIT_OBJECT_0
)
1872 while(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
1873 DispatchMessageA(&msg
);
1874 timeout
= end_time
- GetTickCount();
1875 }while(timeout
> 0);
1880 static WNDPROC def_static_proc
;
1881 static DWORD hittest_no
;
1882 static LRESULT WINAPI
static_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1884 if (msg
== WM_NCHITTEST
)
1886 /* break infinite hittest loop */
1887 if(hittest_no
> 50) return HTCLIENT
;
1891 return def_static_proc(hwnd
, msg
, wp
, lp
);
1901 static DWORD WINAPI
create_static_win(void *arg
)
1903 struct thread_data
*thread_data
= arg
;
1906 win
= CreateWindowA("static", "static", WS_VISIBLE
| WS_POPUP
,
1907 100, 100, 100, 100, 0, NULL
, NULL
, NULL
);
1908 ok(win
!= 0, "CreateWindow failed\n");
1909 def_static_proc
= (void*)SetWindowLongPtrA(win
,
1910 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
1911 thread_data
->win
= win
;
1913 SetEvent(thread_data
->start_event
);
1914 wait_for_event(thread_data
->end_event
, 5000);
1918 static void test_Input_mouse(void)
1920 BOOL got_button_down
, got_button_up
;
1921 HWND hwnd
, button_win
, static_win
;
1922 struct thread_data thread_data
;
1929 SetLastError(0xdeadbeef);
1930 ret
= GetCursorPos(NULL
);
1931 ok(!ret
, "GetCursorPos succeed\n");
1932 ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_NOACCESS
, "error %u\n", GetLastError());
1934 SetLastError(0xdeadbeef);
1935 ret
= GetCursorPos(&pt_org
);
1936 ok(ret
, "GetCursorPos failed\n");
1937 ok(GetLastError() == 0xdeadbeef, "error %u\n", GetLastError());
1939 button_win
= CreateWindowA("button", "button", WS_VISIBLE
| WS_POPUP
,
1940 100, 100, 100, 100, 0, NULL
, NULL
, NULL
);
1941 ok(button_win
!= 0, "CreateWindow failed\n");
1944 hwnd
= WindowFromPoint(pt
);
1945 if (hwnd
!= button_win
)
1947 skip("there's another window covering test window\n");
1948 DestroyWindow(button_win
);
1952 /* simple button click test */
1953 simulate_click(TRUE
, 150, 150);
1954 got_button_down
= got_button_up
= FALSE
;
1955 while (wait_for_message(&msg
))
1957 DispatchMessageA(&msg
);
1959 if (msg
.message
== WM_LBUTTONDOWN
)
1961 got_button_down
= TRUE
;
1963 else if (msg
.message
== WM_LBUTTONUP
)
1965 got_button_up
= TRUE
;
1969 ok(got_button_down
, "expected WM_LBUTTONDOWN message\n");
1970 ok(got_button_up
, "expected WM_LBUTTONUP message\n");
1972 /* click through HTTRANSPARENT child window */
1973 static_win
= CreateWindowA("static", "static", WS_VISIBLE
| WS_CHILD
,
1974 0, 0, 100, 100, button_win
, NULL
, NULL
, NULL
);
1975 ok(static_win
!= 0, "CreateWindow failed\n");
1976 def_static_proc
= (void*)SetWindowLongPtrA(static_win
,
1977 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
1978 simulate_click(FALSE
, 150, 150);
1980 got_button_down
= got_button_up
= FALSE
;
1981 while (wait_for_message(&msg
))
1983 DispatchMessageA(&msg
);
1985 if (msg
.message
== WM_RBUTTONDOWN
)
1987 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
1988 got_button_down
= TRUE
;
1990 else if (msg
.message
== WM_RBUTTONUP
)
1992 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
1993 got_button_up
= TRUE
;
1997 ok(hittest_no
&& hittest_no
<50, "expected WM_NCHITTEST message\n");
1998 ok(got_button_down
, "expected WM_RBUTTONDOWN message\n");
1999 ok(got_button_up
, "expected WM_RBUTTONUP message\n");
2000 DestroyWindow(static_win
);
2002 /* click through HTTRANSPARENT top-level window */
2003 static_win
= CreateWindowA("static", "static", WS_VISIBLE
| WS_POPUP
,
2004 100, 100, 100, 100, 0, NULL
, NULL
, NULL
);
2005 ok(static_win
!= 0, "CreateWindow failed\n");
2006 def_static_proc
= (void*)SetWindowLongPtrA(static_win
,
2007 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
2008 simulate_click(TRUE
, 150, 150);
2010 got_button_down
= got_button_up
= FALSE
;
2011 while (wait_for_message(&msg
))
2013 DispatchMessageA(&msg
);
2015 if (msg
.message
== WM_LBUTTONDOWN
)
2017 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2018 got_button_down
= TRUE
;
2020 else if (msg
.message
== WM_LBUTTONUP
)
2022 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2023 got_button_up
= TRUE
;
2027 ok(hittest_no
&& hittest_no
<50, "expected WM_NCHITTEST message\n");
2028 todo_wine
ok(got_button_down
, "expected WM_LBUTTONDOWN message\n");
2029 todo_wine
ok(got_button_up
, "expected WM_LBUTTONUP message\n");
2030 DestroyWindow(static_win
);
2032 /* click on HTTRANSPARENT top-level window that belongs to other thread */
2033 thread_data
.start_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2034 ok(thread_data
.start_event
!= NULL
, "CreateEvent failed\n");
2035 thread_data
.end_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2036 ok(thread_data
.end_event
!= NULL
, "CreateEvent failed\n");
2037 thread
= CreateThread(NULL
, 0, create_static_win
, &thread_data
, 0, NULL
);
2038 ok(thread
!= NULL
, "CreateThread failed\n");
2040 got_button_down
= got_button_up
= FALSE
;
2041 WaitForSingleObject(thread_data
.start_event
, INFINITE
);
2042 simulate_click(FALSE
, 150, 150);
2043 while (wait_for_message(&msg
))
2045 DispatchMessageA(&msg
);
2047 if (msg
.message
== WM_RBUTTONDOWN
)
2048 got_button_down
= TRUE
;
2049 else if (msg
.message
== WM_RBUTTONUP
)
2050 got_button_up
= TRUE
;
2052 SetEvent(thread_data
.end_event
);
2053 WaitForSingleObject(thread
, INFINITE
);
2054 CloseHandle(thread
);
2055 ok(hittest_no
&& hittest_no
<50, "expected WM_NCHITTEST message\n");
2056 ok(!got_button_down
, "unexpected WM_RBUTTONDOWN message\n");
2057 ok(!got_button_up
, "unexpected WM_RBUTTONUP message\n");
2059 /* click on HTTRANSPARENT top-level window that belongs to other thread,
2060 * thread input queues are attached */
2061 thread
= CreateThread(NULL
, 0, create_static_win
, &thread_data
, 0, &thread_id
);
2062 ok(thread
!= NULL
, "CreateThread failed\n");
2064 got_button_down
= got_button_up
= FALSE
;
2065 WaitForSingleObject(thread_data
.start_event
, INFINITE
);
2066 ok(AttachThreadInput(thread_id
, GetCurrentThreadId(), TRUE
),
2067 "AttachThreadInput failed\n");
2068 while (wait_for_message(&msg
)) DispatchMessageA(&msg
);
2069 SetWindowPos(thread_data
.win
, button_win
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2070 simulate_click(TRUE
, 150, 150);
2071 while (wait_for_message(&msg
))
2073 DispatchMessageA(&msg
);
2075 if (msg
.message
== WM_LBUTTONDOWN
)
2076 got_button_down
= TRUE
;
2077 else if (msg
.message
== WM_LBUTTONUP
)
2078 got_button_up
= TRUE
;
2080 SetEvent(thread_data
.end_event
);
2081 WaitForSingleObject(thread
, INFINITE
);
2082 todo_wine
ok(hittest_no
> 50, "expected loop with WM_NCHITTEST messages\n");
2083 ok(!got_button_down
, "unexpected WM_LBUTTONDOWN message\n");
2084 ok(!got_button_up
, "unexpected WM_LBUTTONUP message\n");
2086 /* click after SetCapture call */
2087 hwnd
= CreateWindowA("button", "button", WS_VISIBLE
| WS_POPUP
,
2088 0, 0, 100, 100, 0, NULL
, NULL
, NULL
);
2089 ok(hwnd
!= 0, "CreateWindow failed\n");
2090 SetCapture(button_win
);
2091 got_button_down
= got_button_up
= FALSE
;
2092 simulate_click(FALSE
, 50, 50);
2093 while (wait_for_message(&msg
))
2095 DispatchMessageA(&msg
);
2097 if (msg
.message
== WM_RBUTTONDOWN
)
2099 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2100 got_button_down
= TRUE
;
2102 else if (msg
.message
== WM_RBUTTONUP
)
2104 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2105 got_button_up
= TRUE
;
2109 ok(got_button_down
, "expected WM_RBUTTONDOWN message\n");
2110 ok(got_button_up
, "expected WM_RBUTTONUP message\n");
2111 DestroyWindow(hwnd
);
2113 /* click on child window after SetCapture call */
2114 hwnd
= CreateWindowA("button", "button2", WS_VISIBLE
| WS_CHILD
,
2115 0, 0, 100, 100, button_win
, NULL
, NULL
, NULL
);
2116 ok(hwnd
!= 0, "CreateWindow failed\n");
2117 got_button_down
= got_button_up
= FALSE
;
2118 simulate_click(TRUE
, 150, 150);
2119 while (wait_for_message(&msg
))
2121 DispatchMessageA(&msg
);
2123 if (msg
.message
== WM_LBUTTONDOWN
)
2125 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2126 got_button_down
= TRUE
;
2128 else if (msg
.message
== WM_LBUTTONUP
)
2130 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2131 got_button_up
= TRUE
;
2135 ok(got_button_down
, "expected WM_LBUTTONDOWN message\n");
2136 ok(got_button_up
, "expected WM_LBUTTONUP message\n");
2137 DestroyWindow(hwnd
);
2138 ok(ReleaseCapture(), "ReleaseCapture failed\n");
2139 SetCursorPos(pt_org
.x
, pt_org
.y
);
2141 CloseHandle(thread_data
.start_event
);
2142 CloseHandle(thread_data
.end_event
);
2143 DestroyWindow(button_win
);
2147 static LRESULT WINAPI
MsgCheckProcA(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2149 if (message
== WM_USER
+1)
2151 HWND hwnd
= (HWND
)lParam
;
2152 ok(GetFocus() == hwnd
, "thread expected focus %p, got %p\n", hwnd
, GetFocus());
2153 ok(GetActiveWindow() == hwnd
, "thread expected active %p, got %p\n", hwnd
, GetActiveWindow());
2155 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2168 static DWORD WINAPI
thread_proc(void *param
)
2171 struct wnd_event
*wnd_event
= param
;
2174 if (wnd_event
->wait_event
)
2176 ok(WaitForSingleObject(wnd_event
->wait_event
, INFINITE
) == WAIT_OBJECT_0
,
2177 "WaitForSingleObject failed\n");
2178 CloseHandle(wnd_event
->wait_event
);
2181 if (wnd_event
->attach_from
)
2183 ret
= AttachThreadInput(wnd_event
->attach_from
, GetCurrentThreadId(), TRUE
);
2184 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2187 if (wnd_event
->attach_to
)
2189 ret
= AttachThreadInput(GetCurrentThreadId(), wnd_event
->attach_to
, TRUE
);
2190 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2193 wnd_event
->hwnd
= CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW
,
2194 100, 100, 200, 200, 0, 0, 0, NULL
);
2195 ok(wnd_event
->hwnd
!= 0, "Failed to create overlapped window\n");
2197 if (wnd_event
->setWindows
)
2199 SetFocus(wnd_event
->hwnd
);
2200 SetActiveWindow(wnd_event
->hwnd
);
2203 SetEvent(wnd_event
->start_event
);
2205 while (GetMessageA(&msg
, 0, 0, 0))
2207 TranslateMessage(&msg
);
2208 DispatchMessageA(&msg
);
2214 static void test_attach_input(void)
2219 struct wnd_event wnd_event
;
2223 cls
.lpfnWndProc
= MsgCheckProcA
;
2226 cls
.hInstance
= GetModuleHandleA(0);
2228 cls
.hCursor
= LoadCursorW( NULL
, (LPCWSTR
)IDC_ARROW
);
2229 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2230 cls
.lpszMenuName
= NULL
;
2231 cls
.lpszClassName
= "TestWindowClass";
2232 if(!RegisterClassA(&cls
)) return;
2234 wnd_event
.wait_event
= NULL
;
2235 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2236 wnd_event
.attach_from
= 0;
2237 wnd_event
.attach_to
= 0;
2238 wnd_event
.setWindows
= FALSE
;
2239 if (!wnd_event
.start_event
)
2241 win_skip("skipping interthread message test under win9x\n");
2245 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2246 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2248 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2249 CloseHandle(wnd_event
.start_event
);
2251 ourWnd
= CreateWindowExA(0, "TestWindowClass", NULL
, WS_OVERLAPPEDWINDOW
,
2252 0, 0, 0, 0, 0, 0, 0, NULL
);
2253 ok(ourWnd
!= 0, "failed to create ourWnd window\n");
2255 Wnd2
= CreateWindowExA(0, "TestWindowClass", NULL
, WS_OVERLAPPEDWINDOW
,
2256 0, 0, 0, 0, 0, 0, 0, NULL
);
2257 ok(Wnd2
!= 0, "failed to create Wnd2 window\n");
2260 SetActiveWindow(ourWnd
);
2262 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2263 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2265 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2266 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2268 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)ourWnd
);
2270 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2271 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2272 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2273 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2275 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, 0);
2277 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2278 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2280 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2281 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2282 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)ourWnd
);
2284 SetActiveWindow(Wnd2
);
2286 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2287 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2289 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)Wnd2
);
2291 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2292 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2293 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2294 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2296 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, 0);
2298 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2299 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2301 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2302 CloseHandle(hThread
);
2304 wnd_event
.wait_event
= NULL
;
2305 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2306 wnd_event
.attach_from
= 0;
2307 wnd_event
.attach_to
= 0;
2308 wnd_event
.setWindows
= TRUE
;
2310 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2311 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2313 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2314 CloseHandle(wnd_event
.start_event
);
2317 SetActiveWindow(ourWnd
);
2319 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2320 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2322 ok(GetActiveWindow() == wnd_event
.hwnd
, "expected active %p, got %p\n", wnd_event
.hwnd
, GetActiveWindow());
2323 ok(GetFocus() == wnd_event
.hwnd
, "expected focus %p, got %p\n", wnd_event
.hwnd
, GetFocus());
2325 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)wnd_event
.hwnd
);
2327 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2328 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2330 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
2331 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
2333 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)wnd_event
.hwnd
);
2335 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2336 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2338 ok(GetActiveWindow() == wnd_event
.hwnd
, "expected active %p, got %p\n", wnd_event
.hwnd
, GetActiveWindow());
2339 ok(GetFocus() == wnd_event
.hwnd
, "expected focus %p, got %p\n", wnd_event
.hwnd
, GetFocus());
2341 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)wnd_event
.hwnd
);
2344 SetActiveWindow(Wnd2
);
2345 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2346 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2348 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)Wnd2
);
2350 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2351 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2353 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2354 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2356 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, 0);
2358 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2359 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2361 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2362 CloseHandle(hThread
);
2364 wnd_event
.wait_event
= CreateEventW(NULL
, 0, 0, NULL
);
2365 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2366 wnd_event
.attach_from
= 0;
2367 wnd_event
.attach_to
= 0;
2368 wnd_event
.setWindows
= TRUE
;
2370 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2371 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2373 SetLastError(0xdeadbeef);
2374 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2375 ok(!ret
, "AttachThreadInput succeeded\n");
2376 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| broken(GetLastError() == 0xdeadbeef) /* <= Win XP */,
2377 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2379 SetLastError(0xdeadbeef);
2380 ret
= AttachThreadInput(tid
, GetCurrentThreadId(), TRUE
);
2381 ok(!ret
, "AttachThreadInput succeeded\n");
2382 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| broken(GetLastError() == 0xdeadbeef) /* <= Win XP */,
2383 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2385 SetEvent(wnd_event
.wait_event
);
2387 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2388 CloseHandle(wnd_event
.start_event
);
2390 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2391 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2393 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2394 CloseHandle(hThread
);
2396 wnd_event
.wait_event
= NULL
;
2397 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2398 wnd_event
.attach_from
= GetCurrentThreadId();
2399 wnd_event
.attach_to
= 0;
2400 wnd_event
.setWindows
= FALSE
;
2403 SetActiveWindow(ourWnd
);
2405 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2406 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2408 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2409 CloseHandle(wnd_event
.start_event
);
2411 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2412 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2414 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2415 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2417 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2418 CloseHandle(hThread
);
2420 wnd_event
.wait_event
= NULL
;
2421 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2422 wnd_event
.attach_from
= 0;
2423 wnd_event
.attach_to
= GetCurrentThreadId();
2424 wnd_event
.setWindows
= FALSE
;
2427 SetActiveWindow(ourWnd
);
2429 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2430 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2432 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2433 CloseHandle(wnd_event
.start_event
);
2435 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2436 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2438 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2439 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2441 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2442 CloseHandle(hThread
);
2443 DestroyWindow(ourWnd
);
2444 DestroyWindow(Wnd2
);
2447 static DWORD WINAPI
get_key_state_thread(void *arg
)
2449 HANDLE
*semaphores
= arg
;
2452 ReleaseSemaphore(semaphores
[0], 1, NULL
);
2453 result
= WaitForSingleObject(semaphores
[1], 1000);
2454 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2456 result
= GetKeyState('X');
2457 ok((result
& 0x8000) || broken(!(result
& 0x8000)), /* > Win 2003 */
2458 "expected that highest bit is set, got %x\n", result
);
2460 ReleaseSemaphore(semaphores
[0], 1, NULL
);
2461 result
= WaitForSingleObject(semaphores
[1], 1000);
2462 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2464 result
= GetKeyState('X');
2465 ok(!(result
& 0x8000), "expected that highest bit is unset, got %x\n", result
);
2470 static void test_GetKeyState(void)
2472 HANDLE semaphores
[2];
2477 semaphores
[0] = CreateSemaphoreA(NULL
, 0, 1, NULL
);
2478 ok(semaphores
[0] != NULL
, "CreateSemaphoreA failed %u\n", GetLastError());
2479 semaphores
[1] = CreateSemaphoreA(NULL
, 0, 1, NULL
);
2480 ok(semaphores
[1] != NULL
, "CreateSemaphoreA failed %u\n", GetLastError());
2482 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
2483 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
2484 ok(hwnd
!= NULL
, "CreateWindowA failed %u\n", GetLastError());
2486 thread
= CreateThread(NULL
, 0, get_key_state_thread
, semaphores
, 0, NULL
);
2487 ok(thread
!= NULL
, "CreateThread failed %u\n", GetLastError());
2488 result
= WaitForSingleObject(semaphores
[0], 1000);
2489 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2492 keybd_event('X', 0, 0, 0);
2494 ReleaseSemaphore(semaphores
[1], 1, NULL
);
2495 result
= WaitForSingleObject(semaphores
[0], 1000);
2496 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2498 keybd_event('X', 0, KEYEVENTF_KEYUP
, 0);
2500 ReleaseSemaphore(semaphores
[1], 1, NULL
);
2501 result
= WaitForSingleObject(thread
, 1000);
2502 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2503 CloseHandle(thread
);
2505 DestroyWindow(hwnd
);
2506 CloseHandle(semaphores
[0]);
2507 CloseHandle(semaphores
[1]);
2510 static void test_OemKeyScan(void)
2512 DWORD ret
, expect
, vkey
, scan
;
2516 for (oem
= 0; oem
< 0x200; oem
++)
2518 ret
= OemKeyScan( oem
);
2520 oem_char
= LOBYTE( oem
);
2521 /* OemKeyScan returns -1 for any character that cannot be mapped,
2522 * whereas OemToCharBuff changes unmappable characters to question
2523 * marks. The ASCII characters 0-127, including the real question mark
2524 * character, are all mappable and are the same in all OEM codepages. */
2525 if (!OemToCharBuffW( &oem_char
, &wchr
, 1 ) || (wchr
== '?' && oem_char
< 0))
2529 vkey
= VkKeyScanW( wchr
);
2530 scan
= MapVirtualKeyW( LOBYTE( vkey
), MAPVK_VK_TO_VSC
);
2537 expect
= vkey
| scan
;
2540 ok( ret
== expect
, "%04x: got %08x expected %08x\n", oem
, ret
, expect
);
2546 init_function_pointers();
2550 test_Input_blackbox();
2551 test_Input_whitebox();
2552 test_Input_unicode();
2555 else win_skip("SendInput is not available\n");
2558 test_mouse_ll_hook();
2562 test_get_async_key_state();
2563 test_keyboard_layout_name();
2565 test_attach_input();
2569 if(pGetMouseMovePointsEx
)
2570 test_GetMouseMovePointsEx();
2572 win_skip("GetMouseMovePointsEx is not available\n");
2574 if(pGetRawInputDeviceList
)
2575 test_GetRawInputDeviceList();
2577 win_skip("GetRawInputDeviceList is not available\n");