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
57 #include "wine/test.h"
61 static LONG timetag
= 0x10000000;
66 LONG last_syskey_down
;
72 LONG last_hook_syskey_down
;
73 LONG last_hook_syskey_up
;
75 BOOL sendinput_broken
;
78 static UINT (WINAPI
*pSendInput
) (UINT
, INPUT
*, size_t);
79 static int (WINAPI
*pGetMouseMovePointsEx
) (UINT
, LPMOUSEMOVEPOINT
, LPMOUSEMOVEPOINT
, int, DWORD
);
80 static UINT (WINAPI
*pGetRawInputDeviceList
) (PRAWINPUTDEVICELIST
, PUINT
, UINT
);
82 #define MAXKEYEVENTS 12
83 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
84 and only one message */
86 /* keyboard message names, sorted as their value */
87 static const char *MSGNAME
[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
88 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
90 /* keyevents, add more as needed */
92 { ALTDOWN
= 1, ALTUP
, XDOWN
, XUP
, SHIFTDOWN
, SHIFTUP
, CTRLDOWN
, CTRLUP
} KEV
;
94 static const int GETVKEY
[]={0, VK_MENU
, VK_MENU
, 'X', 'X', VK_SHIFT
, VK_SHIFT
, VK_CONTROL
, VK_CONTROL
};
95 /* matching scan codes */
96 static const int GETSCAN
[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
97 /* matching updown events */
98 static const int GETFLAGS
[]={0, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
};
99 /* matching descriptions */
100 static const char *getdesc
[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
102 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
114 #define ADDTOINPUTS(kev) \
115 inputs[evtctr].type = INPUT_KEYBOARD; \
116 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
117 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
118 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETFLAGS[ kev]; \
119 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
120 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
129 /*******************************************
130 * add new test sets here
131 * the software will make all combinations of the
132 * keyevent defined here
134 static const struct {
136 KEV keydwn
[MAXKEYEVENTS
];
137 KEV keyup
[MAXKEYEVENTS
];
139 { 2, { ALTDOWN
, XDOWN
}, { ALTUP
, XUP
}},
140 { 3, { ALTDOWN
, XDOWN
, SHIFTDOWN
}, { ALTUP
, XUP
, SHIFTUP
}},
141 { 3, { ALTDOWN
, XDOWN
, CTRLDOWN
}, { ALTUP
, XUP
, CTRLUP
}},
142 { 3, { SHIFTDOWN
, XDOWN
, CTRLDOWN
}, { SHIFTUP
, XUP
, CTRLUP
}},
143 { 0 } /* mark the end */
146 /**********************adapted from input.c **********************************/
148 static BYTE InputKeyStateTable
[256];
149 static BYTE AsyncKeyStateTable
[256];
150 static BYTE TrackSysKey
= 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
151 or a WM_KEYUP message */
153 static void init_function_pointers(void)
155 HMODULE hdll
= GetModuleHandleA("user32");
157 #define GET_PROC(func) \
158 p ## func = (void*)GetProcAddress(hdll, #func); \
160 trace("GetProcAddress(%s) failed\n", #func);
163 GET_PROC(GetMouseMovePointsEx
)
164 GET_PROC(GetRawInputDeviceList
)
169 static int KbdMessage( KEV kev
, WPARAM
*pwParam
, LPARAM
*plParam
)
172 int VKey
= GETVKEY
[kev
];
175 flags
= LOBYTE(GETSCAN
[kev
]);
176 if (GETFLAGS
[kev
] & KEYEVENTF_EXTENDEDKEY
) flags
|= KF_EXTENDED
;
178 if (GETFLAGS
[kev
] & KEYEVENTF_KEYUP
)
181 if( (InputKeyStateTable
[VK_MENU
] & 0x80) && (
182 (VKey
== VK_MENU
) || (VKey
== VK_CONTROL
) ||
183 !(InputKeyStateTable
[VK_CONTROL
] & 0x80))) {
184 if( TrackSysKey
== VK_MENU
|| /* <ALT>-down/<ALT>-up sequence */
185 (VKey
!= VK_MENU
)) /* <ALT>-down...<something else>-up */
186 message
= WM_SYSKEYUP
;
189 InputKeyStateTable
[VKey
] &= ~0x80;
190 flags
|= KF_REPEAT
| KF_UP
;
194 if (InputKeyStateTable
[VKey
] & 0x80) flags
|= KF_REPEAT
;
195 if (!(InputKeyStateTable
[VKey
] & 0x80)) InputKeyStateTable
[VKey
] ^= 0x01;
196 InputKeyStateTable
[VKey
] |= 0x80;
197 AsyncKeyStateTable
[VKey
] |= 0x80;
199 message
= WM_KEYDOWN
;
200 if( (InputKeyStateTable
[VK_MENU
] & 0x80) &&
201 !(InputKeyStateTable
[VK_CONTROL
] & 0x80)) {
202 message
= WM_SYSKEYDOWN
;
207 if (InputKeyStateTable
[VK_MENU
] & 0x80) flags
|= KF_ALTDOWN
;
209 if( plParam
) *plParam
= MAKELPARAM( 1, flags
);
210 if( pwParam
) *pwParam
= VKey
;
214 /****************************** end copy input.c ****************************/
217 * . prepare the keyevents for SendInputs
218 * . calculate the "expected" messages
219 * . Send the events to our window
220 * . retrieve the messages from the input queue
223 static BOOL
do_test( HWND hwnd
, int seqnr
, const KEV td
[] )
225 INPUT inputs
[MAXKEYEVENTS
];
226 KMSG expmsg
[MAXKEYEVENTS
];
233 TrackSysKey
=0; /* see input.c */
234 for( i
= 0; i
< MAXKEYEVENTS
; i
++) {
236 strcat(buf
, getdesc
[td
[i
]]);
238 expmsg
[i
].message
= KbdMessage(td
[i
], &(expmsg
[i
].wParam
), &(expmsg
[i
].lParam
));
240 expmsg
[i
].message
= 0;
242 for( kmctr
= 0; kmctr
< MAXKEYEVENTS
&& expmsg
[kmctr
].message
; kmctr
++)
244 ok( evtctr
<= MAXKEYEVENTS
, "evtctr is above MAXKEYEVENTS\n" );
245 if( evtctr
!= pSendInput(evtctr
, &inputs
[0], sizeof(INPUT
)))
246 ok (FALSE
, "SendInput failed to send some events\n");
248 if (winetest_debug
> 1)
249 trace("======== key stroke sequence #%d: %s =============\n",
251 while( PeekMessageA(&msg
,hwnd
,WM_KEYFIRST
,WM_KEYLAST
,PM_REMOVE
) ) {
252 if (winetest_debug
> 1)
253 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i
,
254 MSGNAME
[msg
.message
- WM_KEYFIRST
], msg
.wParam
, msg
.lParam
, msg
.time
);
256 ok( msg
.message
== expmsg
[i
].message
&&
257 msg
.wParam
== expmsg
[i
].wParam
&&
258 msg
.lParam
== expmsg
[i
].lParam
,
259 "%u/%u: wrong message %x/%08lx/%08lx expected %s/%08lx/%08lx\n",
260 seqnr
, i
, msg
.message
, msg
.wParam
, msg
.lParam
,
261 MSGNAME
[(expmsg
[i
]).message
- WM_KEYFIRST
], expmsg
[i
].wParam
, expmsg
[i
].lParam
);
265 if (winetest_debug
> 1)
266 trace("%d messages retrieved\n", i
);
269 skip( "simulated keyboard input doesn't work\n" );
272 ok( i
== kmctr
, "message count is wrong: got %d expected: %d\n", i
, kmctr
);
276 /* test all combinations of the specified key events */
277 static BOOL
TestASet( HWND hWnd
, int nrkev
, const KEV kevdwn
[], const KEV kevup
[] )
281 KEV kbuf
[MAXKEYEVENTS
];
282 assert( nrkev
==2 || nrkev
==3);
283 for(i
=0;i
<MAXKEYEVENTS
;i
++) kbuf
[i
]=0;
284 /* two keys involved gives 4 test cases */
286 for(i
=0;i
<nrkev
;i
++) {
287 for(j
=0;j
<nrkev
;j
++) {
289 kbuf
[1] = kevdwn
[1-i
];
291 kbuf
[3] = kevup
[1-j
];
292 if (!do_test( hWnd
, count
++, kbuf
)) return FALSE
;
296 /* three keys involved gives 36 test cases */
298 for(i
=0;i
<nrkev
;i
++){
299 for(j
=0;j
<nrkev
;j
++){
301 for(k
=0;k
<nrkev
;k
++){
302 if(k
==i
|| k
==j
) continue;
303 for(l
=0;l
<nrkev
;l
++){
304 for(m
=0;m
<nrkev
;m
++){
306 for(n
=0;n
<nrkev
;n
++){
307 if(n
==l
||n
==m
) continue;
314 if (!do_test( hWnd
, count
++, kbuf
)) return FALSE
;
325 /* test each set specified in the global testkeyset array */
326 static void TestSysKeys( HWND hWnd
)
329 for(i
=0; testkeyset
[i
].nrkev
;i
++)
330 if (!TestASet( hWnd
, testkeyset
[i
].nrkev
, testkeyset
[i
].keydwn
, testkeyset
[i
].keyup
)) break;
333 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
336 return DefWindowProcA( hWnd
, msg
, wParam
, lParam
);
339 static void test_Input_whitebox(void)
343 HANDLE hInstance
= GetModuleHandleA( NULL
);
345 wclass
.lpszClassName
= "InputSysKeyTestClass";
346 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
347 wclass
.lpfnWndProc
= WndProc
;
348 wclass
.hInstance
= hInstance
;
349 wclass
.hIcon
= LoadIconA( 0, (LPCSTR
)IDI_APPLICATION
);
350 wclass
.hCursor
= LoadCursorA( NULL
, (LPCSTR
)IDC_ARROW
);
351 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1 );
352 wclass
.lpszMenuName
= 0;
353 wclass
.cbClsExtra
= 0;
354 wclass
.cbWndExtra
= 0;
355 RegisterClassA( &wclass
);
356 /* create the test window that will receive the keystrokes */
357 hWndTest
= CreateWindowA( wclass
.lpszClassName
, "InputSysKeyTest",
358 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
359 NULL
, NULL
, hInstance
, NULL
);
361 ShowWindow( hWndTest
, SW_SHOW
);
362 SetWindowPos( hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
363 SetForegroundWindow( hWndTest
);
364 UpdateWindow( hWndTest
);
366 /* flush pending messages */
367 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
369 SetFocus( hWndTest
);
370 TestSysKeys( hWndTest
);
371 DestroyWindow(hWndTest
);
374 static inline BOOL
is_keyboard_message( UINT message
)
376 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
379 static inline BOOL
is_mouse_message( UINT message
)
381 return (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
);
384 /* try to make sure pending X events have been processed before continuing */
385 static void empty_message_queue(void)
389 int min_timeout
= 50;
390 DWORD time
= GetTickCount() + diff
;
394 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
395 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
397 if (is_keyboard_message(msg
.message
) || is_mouse_message(msg
.message
))
398 ok(msg
.time
!= 0, "message %#x has time set to 0\n", msg
.message
);
400 TranslateMessage(&msg
);
401 DispatchMessageA(&msg
);
403 diff
= time
- GetTickCount();
407 struct transition_s
{
427 UINT message
; /* the WM_* code */
428 msg_flags_t flags
; /* message props */
429 WPARAM wParam
; /* expected value of wParam */
430 LPARAM lParam
; /* expected value of lParam */
433 static const struct sendinput_test_s
{
437 struct transition_s expected_transitions
[MAXKEYEVENTS
+1];
438 struct message expected_messages
[MAXKEYMESSAGES
+1];
439 } sendinput_test
[] = {
442 {VK_LMENU
, 0, FALSE
, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
443 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_LMENU
}, {WM_SYSKEYDOWN
}, {0}}},
444 {'F', 0, FALSE
, {{'F', 0x00}, {0}},
445 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
},
447 {WM_SYSCOMMAND
}, {0}}},
448 {'F', KEYEVENTF_KEYUP
, FALSE
, {{'F', 0x80}, {0}},
449 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
450 {VK_LMENU
, KEYEVENTF_KEYUP
, FALSE
, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
451 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
455 {VK_LCONTROL
, 0, FALSE
, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
456 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
457 {'O', 0, FALSE
, {{'O', 0x00}, {0}},
458 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
459 {'O', KEYEVENTF_KEYUP
, FALSE
, {{'O', 0x80}, {0}},
460 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
461 {VK_LCONTROL
, KEYEVENTF_KEYUP
, FALSE
, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
462 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
464 /* test ALT+CTRL+X */
466 {VK_LMENU
, 0, FALSE
, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
467 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
}, {0}}},
468 {VK_LCONTROL
, 0, FALSE
, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
469 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
470 {'X', 0, FALSE
, {{'X', 0x00}, {0}},
471 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
472 {'X', KEYEVENTF_KEYUP
, FALSE
, {{'X', 0x80}, {0}},
473 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
474 {VK_LCONTROL
, KEYEVENTF_KEYUP
, FALSE
, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
475 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
476 {VK_LMENU
, KEYEVENTF_KEYUP
, FALSE
, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
477 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
481 {VK_LSHIFT
, 0, FALSE
, {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
482 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
483 {'A', 0, FALSE
, {{'A', 0x00}, {0}},
484 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
485 {'A', KEYEVENTF_KEYUP
, FALSE
, {{'A', 0x80}, {0}},
486 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
487 {VK_LSHIFT
, KEYEVENTF_KEYUP
, FALSE
, {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
488 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
489 /* test L-SHIFT & R-SHIFT: */
490 /* RSHIFT == LSHIFT */
492 {VK_RSHIFT
, 0, FALSE
,
493 /* recent windows versions (>= w2k3) correctly report an RSHIFT transition */
494 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00, TRUE
}, {VK_RSHIFT
, 0x00, TRUE
}, {0}},
495 {{WM_KEYDOWN
, hook
|wparam
, VK_RSHIFT
},
497 {VK_RSHIFT
, KEYEVENTF_KEYUP
, FALSE
,
498 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80, TRUE
}, {VK_RSHIFT
, 0x80, TRUE
}, {0}},
499 {{WM_KEYUP
, hook
, hook
|wparam
, VK_RSHIFT
},
502 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
504 {VK_LSHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
505 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
506 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_EXTENDED
},
507 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
508 {VK_LSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
509 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
510 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
511 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
512 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
514 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
515 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
516 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
517 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
518 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
519 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
520 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
521 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
523 /* Note about wparam for hook with generic key (VK_SHIFT, VK_CONTROL, VK_MENU):
524 win2k - sends to hook whatever we generated here
525 winXP+ - Attempts to convert key to L/R key but not always correct
527 /* SHIFT == LSHIFT */
530 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
531 {{WM_KEYDOWN
, hook
/* |wparam */|lparam
, VK_SHIFT
, 0},
532 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
533 {VK_SHIFT
, KEYEVENTF_KEYUP
, FALSE
,
534 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
535 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_UP
},
536 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
537 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
539 {VK_SHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
540 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
541 {{WM_KEYDOWN
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_EXTENDED
},
542 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
543 {VK_SHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
544 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
545 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_SHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
546 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
548 /* test L-CONTROL & R-CONTROL: */
549 /* RCONTROL == LCONTROL */
551 {VK_RCONTROL
, 0, FALSE
,
552 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
553 {{WM_KEYDOWN
, hook
|wparam
, VK_RCONTROL
},
554 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
555 {VK_RCONTROL
, KEYEVENTF_KEYUP
, FALSE
,
556 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
557 {{WM_KEYUP
, hook
|wparam
, VK_RCONTROL
},
558 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
559 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
561 {VK_LCONTROL
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
562 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
563 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_EXTENDED
},
564 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
565 {VK_LCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
566 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
567 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
568 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
569 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
571 {VK_RCONTROL
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
572 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
573 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_EXTENDED
},
574 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
575 {VK_RCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
576 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
577 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
578 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
579 /* CONTROL == LCONTROL */
581 {VK_CONTROL
, 0, FALSE
,
582 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
583 {{WM_KEYDOWN
, hook
/*|wparam, VK_CONTROL*/},
584 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
585 {VK_CONTROL
, KEYEVENTF_KEYUP
, FALSE
,
586 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
587 {{WM_KEYUP
, hook
/*|wparam, VK_CONTROL*/},
588 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
589 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
591 {VK_CONTROL
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
592 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
593 {{WM_KEYDOWN
, hook
/*|wparam*/|lparam
, VK_CONTROL
, LLKHF_EXTENDED
},
594 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
595 {VK_CONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
596 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
597 {{WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_CONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
598 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
600 /* test L-MENU & R-MENU: */
604 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {VK_CONTROL
, 0x00, 1}, {VK_LCONTROL
, 0x01, 1}, {0}},
605 {{WM_SYSKEYDOWN
, hook
|wparam
|optional
, VK_LCONTROL
},
606 {WM_SYSKEYDOWN
, hook
|wparam
, VK_RMENU
},
607 {WM_KEYDOWN
, wparam
|lparam
|optional
, VK_CONTROL
, 0},
608 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
609 {VK_RMENU
, KEYEVENTF_KEYUP
, TRUE
,
610 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {VK_CONTROL
, 0x81, 1}, {VK_LCONTROL
, 0x80, 1}, {0}},
611 {{WM_KEYUP
, hook
|wparam
|optional
, VK_LCONTROL
},
612 {WM_KEYUP
, hook
|wparam
, VK_RMENU
},
613 {WM_SYSKEYUP
, wparam
|lparam
|optional
, VK_CONTROL
, KF_UP
},
614 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
615 {WM_SYSCOMMAND
, optional
}, {0}}},
616 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
618 {VK_LMENU
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
619 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
620 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_EXTENDED
},
621 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
622 {VK_LMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, TRUE
,
623 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
624 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
625 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
626 {WM_SYSCOMMAND
}, {0}}},
627 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
629 {VK_RMENU
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
630 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {VK_CONTROL
, 0x00, 1}, {VK_LCONTROL
, 0x01, 1}, {0}},
631 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
|optional
, VK_LCONTROL
, 0},
632 {WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_EXTENDED
},
633 {WM_KEYDOWN
, wparam
|lparam
|optional
, VK_CONTROL
, 0},
634 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
635 {VK_RMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, TRUE
,
636 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {VK_CONTROL
, 0x81, 1}, {VK_LCONTROL
, 0x80, 1}, {0}},
637 {{WM_KEYUP
, hook
|wparam
|lparam
|optional
, VK_LCONTROL
, LLKHF_UP
},
638 {WM_KEYUP
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
639 {WM_SYSKEYUP
, wparam
|lparam
|optional
, VK_CONTROL
, KF_UP
},
640 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
641 {WM_SYSCOMMAND
, optional
}, {0}}},
645 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
646 {{WM_SYSKEYDOWN
, hook
/*|wparam, VK_MENU*/},
647 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
648 {VK_MENU
, KEYEVENTF_KEYUP
, TRUE
,
649 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
650 {{WM_KEYUP
, hook
/*|wparam, VK_MENU*/},
651 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
652 {WM_SYSCOMMAND
}, {0}}},
653 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
655 {VK_MENU
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
656 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {VK_CONTROL
, 0x00, 1}, {VK_LCONTROL
, 0x01, 1}, {0}},
657 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
|optional
, VK_CONTROL
, 0},
658 {WM_SYSKEYDOWN
, hook
/*|wparam*/|lparam
, VK_MENU
, LLKHF_EXTENDED
},
659 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
660 {VK_MENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, TRUE
,
661 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {VK_CONTROL
, 0x81, 1}, {VK_LCONTROL
, 0x80, 1}, {0}},
662 {{WM_KEYUP
, hook
|wparam
|lparam
|optional
, VK_CONTROL
, LLKHF_UP
},
663 {WM_KEYUP
, hook
/*|wparam*/|lparam
, VK_MENU
, LLKHF_UP
|LLKHF_EXTENDED
},
664 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
665 {WM_SYSCOMMAND
}, {0}}},
667 /* test LSHIFT & RSHIFT */
669 {VK_LSHIFT
, 0, FALSE
,
670 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
671 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, 0},
672 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
673 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, FALSE
,
674 {{VK_RSHIFT
, 0x00}, {0}},
675 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
676 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
677 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, FALSE
,
678 {{VK_RSHIFT
, 0x80}, {0}},
679 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
680 {WM_KEYUP
, optional
}, {0}}},
681 {VK_LSHIFT
, KEYEVENTF_KEYUP
, FALSE
,
682 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
683 {{WM_KEYUP
, hook
|wparam
, VK_LSHIFT
},
684 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
686 {0, 0, FALSE
, {{0}}, {{0}}} /* end */
689 static struct message sent_messages
[MAXKEYMESSAGES
];
690 static UINT sent_messages_cnt
;
692 /* Verify that only specified key state transitions occur */
693 static void compare_and_check(int id
, BYTE
*ks1
, BYTE
*ks2
, const struct sendinput_test_s
*test
)
695 int i
, failcount
= 0;
696 const struct transition_s
*t
= test
->expected_transitions
;
698 const struct message
*expected
= test
->expected_messages
;
701 BOOL matched
= ((ks1
[t
->wVk
]&0x80) == (t
->before_state
&0x80)
702 && (ks2
[t
->wVk
]&0x80) == (~t
->before_state
&0x80));
704 if (!matched
&& !t
->optional
&& test
->_todo_wine
)
708 ok(matched
, "%2d (%x/%x): %02x from %02x -> %02x "
709 "instead of %02x -> %02x\n", id
, test
->wVk
, test
->dwFlags
,
710 t
->wVk
, ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
711 ~t
->before_state
&0x80);
714 ok(matched
|| t
->optional
, "%2d (%x/%x): %02x from %02x -> %02x "
715 "instead of %02x -> %02x\n", id
, test
->wVk
, test
->dwFlags
,
716 t
->wVk
, ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
717 ~t
->before_state
&0x80);
719 ks2
[t
->wVk
] = ks1
[t
->wVk
]; /* clear the match */
722 for (i
= 0; i
< 256; i
++)
723 if (ks2
[i
] != ks1
[i
] && test
->_todo_wine
)
727 ok(FALSE
, "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
728 id
, test
->wVk
, test
->dwFlags
, i
, ks1
[i
], ks2
[i
]);
731 ok(ks2
[i
] == ks1
[i
], "%2d (%x/%x): %02x from %02x -> %02x unexpected\n",
732 id
, test
->wVk
, test
->dwFlags
, i
, ks1
[i
], ks2
[i
]);
734 while (expected
->message
&& actual_cnt
< sent_messages_cnt
)
736 const struct message
*actual
= &sent_messages
[actual_cnt
];
738 if (expected
->message
== actual
->message
)
740 if (expected
->flags
& wparam
)
742 if ((expected
->flags
& optional
) && (expected
->wParam
!= actual
->wParam
))
747 if (expected
->wParam
!= actual
->wParam
&& test
->_todo_wine
)
751 ok(FALSE
, "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
752 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
755 ok(expected
->wParam
== actual
->wParam
,
756 "%2d (%x/%x): in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
757 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
759 if (expected
->flags
& lparam
)
761 if (expected
->lParam
!= actual
->lParam
&& test
->_todo_wine
)
765 ok(FALSE
, "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
766 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
769 ok(expected
->lParam
== actual
->lParam
,
770 "%2d (%x/%x): in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
771 id
, test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
773 ok((expected
->flags
& hook
) == (actual
->flags
& hook
),
774 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
775 id
, test
->wVk
, test
->dwFlags
, expected
->message
);
778 else if (expected
->flags
& optional
)
783 /* NT4 doesn't send SYSKEYDOWN/UP to hooks, only KEYDOWN/UP */
784 else if ((expected
->flags
& hook
) &&
785 (expected
->message
== WM_SYSKEYDOWN
|| expected
->message
== WM_SYSKEYUP
) &&
786 (actual
->message
== expected
->message
- 4))
788 ok((expected
->flags
& hook
) == (actual
->flags
& hook
),
789 "%2d (%x/%x): the msg 0x%04x should have been sent by a hook\n",
790 id
, test
->wVk
, test
->dwFlags
, expected
->message
);
792 /* For VK_RMENU, at least localized Win2k/XP sends KEYDOWN/UP
793 * instead of SYSKEYDOWN/UP to the WNDPROC */
794 else if (test
->wVk
== VK_RMENU
&& !(expected
->flags
& hook
) &&
795 (expected
->message
== WM_SYSKEYDOWN
|| expected
->message
== WM_SYSKEYUP
) &&
796 (actual
->message
== expected
->message
- 4))
798 ok(expected
->wParam
== actual
->wParam
&& expected
->lParam
== actual
->lParam
,
799 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
800 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
802 else if (test
->_todo_wine
)
807 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
808 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
812 "%2d (%x/%x): the msg 0x%04x was expected, but got msg 0x%04x instead\n",
813 id
, test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
818 /* skip all optional trailing messages */
819 while (expected
->message
&& (expected
->flags
& optional
))
823 if (expected
->message
|| actual_cnt
< sent_messages_cnt
)
825 if (test
->_todo_wine
)
829 ok(FALSE
, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
830 id
, test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
833 ok(FALSE
, "%2d (%x/%x): the msg sequence is not complete: expected %04x - actual %04x\n",
834 id
, test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
837 if( test
->_todo_wine
&& !failcount
) /* succeeded yet marked todo */
839 ok(TRUE
, "%2d (%x/%x): marked \"todo_wine\" but succeeds\n", id
, test
->wVk
, test
->dwFlags
);
841 sent_messages_cnt
= 0;
844 /* WndProc2 checks that we get at least the messages specified */
845 static LRESULT CALLBACK
WndProc2(HWND hWnd
, UINT Msg
, WPARAM wParam
,
848 if (winetest_debug
> 1) trace("MSG: %8x W:%8lx L:%8lx\n", Msg
, wParam
, lParam
);
850 if (Msg
!= WM_PAINT
&&
852 Msg
!= WM_SYNCPAINT
&&
853 Msg
!= WM_ERASEBKGND
&&
854 Msg
!= WM_NCHITTEST
&&
857 Msg
!= WM_IME_SELECT
&&
858 Msg
!= WM_DEVICECHANGE
&&
859 Msg
!= WM_TIMECHANGE
)
861 ok(sent_messages_cnt
< MAXKEYMESSAGES
, "Too many messages\n");
862 if (sent_messages_cnt
< MAXKEYMESSAGES
)
864 sent_messages
[sent_messages_cnt
].message
= Msg
;
865 sent_messages
[sent_messages_cnt
].flags
= 0;
866 sent_messages
[sent_messages_cnt
].wParam
= wParam
;
867 sent_messages
[sent_messages_cnt
++].lParam
= HIWORD(lParam
) & (KF_UP
|KF_EXTENDED
);
870 return DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
873 static LRESULT CALLBACK
hook_proc(int code
, WPARAM wparam
, LPARAM lparam
)
875 KBDLLHOOKSTRUCT
*hook_info
= (KBDLLHOOKSTRUCT
*)lparam
;
877 if (code
== HC_ACTION
)
879 ok(sent_messages_cnt
< MAXKEYMESSAGES
, "Too many messages\n");
880 if (sent_messages_cnt
< MAXKEYMESSAGES
)
882 sent_messages
[sent_messages_cnt
].message
= wparam
;
883 sent_messages
[sent_messages_cnt
].flags
= hook
;
884 sent_messages
[sent_messages_cnt
].wParam
= hook_info
->vkCode
;
885 sent_messages
[sent_messages_cnt
++].lParam
= hook_info
->flags
& (LLKHF_UP
|LLKHF_EXTENDED
);
888 if(0) /* For some reason not stable on Wine */
890 if (wparam
== WM_KEYDOWN
|| wparam
== WM_SYSKEYDOWN
)
891 ok(!(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000), "key %x should be up\n", hook_info
->vkCode
);
892 else if (wparam
== WM_KEYUP
|| wparam
== WM_SYSKEYUP
)
893 ok(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000, "key %x should be down\n", hook_info
->vkCode
);
896 if (winetest_debug
> 1)
897 trace("Hook: w=%lx vk:%8x sc:%8x fl:%8x %lx\n", wparam
,
898 hook_info
->vkCode
, hook_info
->scanCode
, hook_info
->flags
, hook_info
->dwExtraInfo
);
900 return CallNextHookEx( 0, code
, wparam
, lparam
);
902 static void test_Input_blackbox(void)
906 BYTE ks1
[256], ks2
[256];
907 LONG_PTR prevWndProc
;
911 if (GetKeyboardLayout(0) != (HKL
)(ULONG_PTR
)0x04090409)
913 skip("Skipping Input_blackbox test on non-US keyboard\n");
916 window
= CreateWindowA("Static", NULL
, WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
917 |WS_VISIBLE
, 0, 0, 200, 60, NULL
, NULL
,
919 ok(window
!= NULL
, "error: %d\n", (int) GetLastError());
920 SetWindowPos( window
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
921 SetForegroundWindow( window
);
923 if (!(hook
= SetWindowsHookExA(WH_KEYBOARD_LL
, hook_proc
, GetModuleHandleA( NULL
), 0)))
925 DestroyWindow(window
);
926 win_skip("WH_KEYBOARD_LL is not supported\n");
930 /* must process all initial messages, otherwise X11DRV_KeymapNotify unsets
931 * key state set by SendInput(). */
932 empty_message_queue();
934 prevWndProc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
) WndProc2
);
935 ok(prevWndProc
!= 0 || (prevWndProc
== 0 && GetLastError() == 0),
936 "error: %d\n", (int) GetLastError());
938 i
.type
= INPUT_KEYBOARD
;
940 i
.u
.ki
.dwExtraInfo
= 0;
942 for (ii
= 0; ii
< sizeof(sendinput_test
)/sizeof(struct sendinput_test_s
)-1;
944 GetKeyboardState(ks1
);
945 i
.u
.ki
.wScan
= ii
+1 /* useful for debugging */;
946 i
.u
.ki
.dwFlags
= sendinput_test
[ii
].dwFlags
;
947 i
.u
.ki
.wVk
= sendinput_test
[ii
].wVk
;
948 pSendInput(1, (INPUT
*)&i
, sizeof(TEST_INPUT
));
949 empty_message_queue();
950 GetKeyboardState(ks2
);
951 if (!ii
&& sent_messages_cnt
<= 1 && !memcmp( ks1
, ks2
, sizeof(ks1
) ))
953 win_skip( "window doesn't receive the queued input\n" );
954 /* release the key */
955 i
.u
.ki
.dwFlags
|= KEYEVENTF_KEYUP
;
956 pSendInput(1, (INPUT
*)&i
, sizeof(TEST_INPUT
));
959 compare_and_check(ii
, ks1
, ks2
, &sendinput_test
[ii
]);
962 empty_message_queue();
963 DestroyWindow(window
);
964 UnhookWindowsHookEx(hook
);
967 static void reset_key_status(void)
969 key_status
.last_key_down
= -1;
970 key_status
.last_key_up
= -1;
971 key_status
.last_syskey_down
= -1;
972 key_status
.last_syskey_up
= -1;
973 key_status
.last_char
= -1;
974 key_status
.last_syschar
= -1;
975 key_status
.last_hook_down
= -1;
976 key_status
.last_hook_up
= -1;
977 key_status
.last_hook_syskey_down
= -1;
978 key_status
.last_hook_syskey_up
= -1;
979 key_status
.expect_alt
= FALSE
;
980 key_status
.sendinput_broken
= FALSE
;
983 static void test_unicode_keys(HWND hwnd
, HHOOK hook
)
985 TEST_INPUT inputs
[2];
988 /* init input data that never changes */
989 inputs
[1].type
= inputs
[0].type
= INPUT_KEYBOARD
;
990 inputs
[1].u
.ki
.dwExtraInfo
= inputs
[0].u
.ki
.dwExtraInfo
= 0;
991 inputs
[1].u
.ki
.time
= inputs
[0].u
.ki
.time
= 0;
993 /* pressing & releasing a single unicode character */
994 inputs
[0].u
.ki
.wVk
= 0;
995 inputs
[0].u
.ki
.wScan
= 0x3c0;
996 inputs
[0].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
;
999 pSendInput(1, (INPUT
*)inputs
, sizeof(INPUT
));
1000 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1001 if(msg
.message
== WM_KEYDOWN
&& msg
.wParam
== VK_PACKET
){
1002 TranslateMessage(&msg
);
1004 DispatchMessageW(&msg
);
1006 if(!key_status
.sendinput_broken
){
1007 ok(key_status
.last_key_down
== VK_PACKET
,
1008 "Last keydown msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_key_down
);
1009 ok(key_status
.last_char
== 0x3c0,
1010 "Last char msg wparam should have been 0x3c0 (was: 0x%x)\n", key_status
.last_char
);
1012 ok(key_status
.last_hook_down
== 0x3c0,
1013 "Last hookdown msg should have been 0x3c0, was: 0x%x\n", key_status
.last_hook_down
);
1016 inputs
[1].u
.ki
.wVk
= 0;
1017 inputs
[1].u
.ki
.wScan
= 0x3c0;
1018 inputs
[1].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
| KEYEVENTF_KEYUP
;
1021 pSendInput(1, (INPUT
*)(inputs
+1), sizeof(INPUT
));
1022 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1023 if(msg
.message
== WM_KEYDOWN
&& msg
.wParam
== VK_PACKET
){
1024 TranslateMessage(&msg
);
1026 DispatchMessageW(&msg
);
1028 if(!key_status
.sendinput_broken
){
1029 ok(key_status
.last_key_up
== VK_PACKET
,
1030 "Last keyup msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_key_up
);
1032 ok(key_status
.last_hook_up
== 0x3c0,
1033 "Last hookup msg should have been 0x3c0, was: 0x%x\n", key_status
.last_hook_up
);
1036 /* holding alt, pressing & releasing a unicode character, releasing alt */
1037 inputs
[0].u
.ki
.wVk
= VK_LMENU
;
1038 inputs
[0].u
.ki
.wScan
= 0;
1039 inputs
[0].u
.ki
.dwFlags
= 0;
1041 inputs
[1].u
.ki
.wVk
= 0;
1042 inputs
[1].u
.ki
.wScan
= 0x3041;
1043 inputs
[1].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
;
1046 key_status
.expect_alt
= TRUE
;
1047 pSendInput(2, (INPUT
*)inputs
, sizeof(INPUT
));
1048 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1049 if(msg
.message
== WM_SYSKEYDOWN
&& msg
.wParam
== VK_PACKET
){
1050 TranslateMessage(&msg
);
1052 DispatchMessageW(&msg
);
1054 if(!key_status
.sendinput_broken
){
1055 ok(key_status
.last_syskey_down
== VK_PACKET
,
1056 "Last syskeydown msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_syskey_down
);
1057 ok(key_status
.last_syschar
== 0x3041,
1058 "Last syschar msg should have been 0x3041 (was: 0x%x)\n", key_status
.last_syschar
);
1060 ok(key_status
.last_hook_syskey_down
== 0x3041,
1061 "Last hooksysdown msg should have been 0x3041, was: 0x%x\n", key_status
.last_hook_syskey_down
);
1064 inputs
[1].u
.ki
.wVk
= 0;
1065 inputs
[1].u
.ki
.wScan
= 0x3041;
1066 inputs
[1].u
.ki
.dwFlags
= KEYEVENTF_UNICODE
| KEYEVENTF_KEYUP
;
1068 inputs
[0].u
.ki
.wVk
= VK_LMENU
;
1069 inputs
[0].u
.ki
.wScan
= 0;
1070 inputs
[0].u
.ki
.dwFlags
= KEYEVENTF_KEYUP
;
1073 key_status
.expect_alt
= TRUE
;
1074 pSendInput(2, (INPUT
*)inputs
, sizeof(INPUT
));
1075 while(PeekMessageW(&msg
, hwnd
, 0, 0, PM_REMOVE
)){
1076 if(msg
.message
== WM_SYSKEYDOWN
&& msg
.wParam
== VK_PACKET
){
1077 TranslateMessage(&msg
);
1079 DispatchMessageW(&msg
);
1081 if(!key_status
.sendinput_broken
){
1082 ok(key_status
.last_key_up
== VK_PACKET
,
1083 "Last keyup msg should have been VK_PACKET[0x%04x] (was: 0x%x)\n", VK_PACKET
, key_status
.last_key_up
);
1085 ok(key_status
.last_hook_up
== 0x3041,
1086 "Last hook up msg should have been 0x3041, was: 0x%x\n", key_status
.last_hook_up
);
1090 static LRESULT CALLBACK
unicode_wnd_proc( HWND hWnd
, UINT msg
, WPARAM wParam
,
1095 key_status
.last_key_down
= wParam
;
1098 key_status
.last_syskey_down
= wParam
;
1101 key_status
.last_key_up
= wParam
;
1104 key_status
.last_syskey_up
= wParam
;
1107 key_status
.last_char
= wParam
;
1110 key_status
.last_syschar
= wParam
;
1113 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1116 static LRESULT CALLBACK
llkbd_unicode_hook(int nCode
, WPARAM wParam
, LPARAM lParam
)
1118 if(nCode
== HC_ACTION
){
1119 LPKBDLLHOOKSTRUCT info
= (LPKBDLLHOOKSTRUCT
)lParam
;
1121 key_status
.sendinput_broken
= TRUE
;
1122 win_skip("SendInput doesn't support unicode on this platform\n");
1124 if(key_status
.expect_alt
){
1125 ok(info
->vkCode
== VK_LMENU
, "vkCode should have been VK_LMENU[0x%04x], was: 0x%x\n", VK_LMENU
, info
->vkCode
);
1126 key_status
.expect_alt
= FALSE
;
1128 ok(info
->vkCode
== VK_PACKET
, "vkCode should have been VK_PACKET[0x%04x], was: 0x%x\n", VK_PACKET
, info
->vkCode
);
1132 key_status
.last_hook_down
= info
->scanCode
;
1135 key_status
.last_hook_up
= info
->scanCode
;
1138 key_status
.last_hook_syskey_down
= info
->scanCode
;
1141 key_status
.last_hook_syskey_up
= info
->scanCode
;
1145 return CallNextHookEx(NULL
, nCode
, wParam
, lParam
);
1148 static void test_Input_unicode(void)
1150 WCHAR classNameW
[] = {'I','n','p','u','t','U','n','i','c','o','d','e',
1151 'K','e','y','T','e','s','t','C','l','a','s','s',0};
1152 WCHAR windowNameW
[] = {'I','n','p','u','t','U','n','i','c','o','d','e',
1153 'K','e','y','T','e','s','t',0};
1156 HANDLE hInstance
= GetModuleHandleW(NULL
);
1158 HMODULE hModuleImm32
;
1159 BOOL (WINAPI
*pImmDisableIME
)(DWORD
);
1161 wclass
.lpszClassName
= classNameW
;
1162 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
1163 wclass
.lpfnWndProc
= unicode_wnd_proc
;
1164 wclass
.hInstance
= hInstance
;
1165 wclass
.hIcon
= LoadIconW(0, (LPCWSTR
)IDI_APPLICATION
);
1166 wclass
.hCursor
= LoadCursorW( NULL
, (LPCWSTR
)IDC_ARROW
);
1167 wclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1168 wclass
.lpszMenuName
= 0;
1169 wclass
.cbClsExtra
= 0;
1170 wclass
.cbWndExtra
= 0;
1171 if(!RegisterClassW(&wclass
)){
1172 win_skip("Unicode functions not supported\n");
1176 hModuleImm32
= LoadLibraryA("imm32.dll");
1178 pImmDisableIME
= (void *)GetProcAddress(hModuleImm32
, "ImmDisableIME");
1182 pImmDisableIME
= NULL
;
1183 FreeLibrary(hModuleImm32
);
1185 /* create the test window that will receive the keystrokes */
1186 hWndTest
= CreateWindowW(wclass
.lpszClassName
, windowNameW
,
1187 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
1188 NULL
, NULL
, hInstance
, NULL
);
1191 assert(IsWindowUnicode(hWndTest
));
1193 hook
= SetWindowsHookExW(WH_KEYBOARD_LL
, llkbd_unicode_hook
, GetModuleHandleW(NULL
), 0);
1195 win_skip("unable to set WH_KEYBOARD_LL hook\n");
1197 ShowWindow(hWndTest
, SW_SHOW
);
1198 SetWindowPos(hWndTest
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1199 SetForegroundWindow(hWndTest
);
1200 UpdateWindow(hWndTest
);
1202 /* flush pending messages */
1203 while (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW(&msg
);
1207 test_unicode_keys(hWndTest
, hook
);
1210 UnhookWindowsHookEx(hook
);
1211 DestroyWindow(hWndTest
);
1214 static void test_keynames(void)
1219 for (i
= 0; i
< 512; i
++)
1221 strcpy(buff
, "----");
1222 len
= GetKeyNameTextA(i
<< 16, buff
, sizeof(buff
));
1223 ok(len
|| !buff
[0], "%d: Buffer is not zeroed\n", i
);
1227 static POINT pt_old
, pt_new
;
1228 static BOOL clipped
;
1231 static LRESULT CALLBACK
hook_proc1( int code
, WPARAM wparam
, LPARAM lparam
)
1233 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
1236 if (code
== HC_ACTION
)
1238 /* This is our new cursor position */
1240 /* Should return previous position */
1242 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
1244 /* Should set new position until hook chain is finished. */
1245 pt
.x
= pt_old
.x
+ STEP
;
1246 pt
.y
= pt_old
.y
+ STEP
;
1247 SetCursorPos(pt
.x
, pt
.y
);
1250 ok(pt1
.x
== pt_old
.x
&& pt1
.y
== pt_old
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
1252 ok(pt1
.x
== pt
.x
&& pt1
.y
== pt
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
1254 return CallNextHookEx( 0, code
, wparam
, lparam
);
1257 static LRESULT CALLBACK
hook_proc2( int code
, WPARAM wparam
, LPARAM lparam
)
1259 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
1262 if (code
== HC_ACTION
)
1264 ok(hook
->pt
.x
== pt_new
.x
&& hook
->pt
.y
== pt_new
.y
,
1265 "Wrong hook coords: (%d %d) != (%d,%d)\n", hook
->pt
.x
, hook
->pt
.y
, pt_new
.x
, pt_new
.y
);
1267 /* Should match position set above */
1270 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
1272 ok(pt
.x
== pt_old
.x
+STEP
&& pt
.y
== pt_old
.y
+STEP
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
1274 return CallNextHookEx( 0, code
, wparam
, lparam
);
1277 static void test_mouse_ll_hook(void)
1284 GetCursorPos(&pt_org
);
1285 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
1286 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
1287 SetCursorPos(100, 100);
1289 if (!(hook2
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc2
, GetModuleHandleA(0), 0)))
1291 win_skip( "cannot set MOUSE_LL hook\n" );
1294 hook1
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc1
, GetModuleHandleA(0), 0);
1296 GetCursorPos(&pt_old
);
1297 mouse_event(MOUSEEVENTF_MOVE
, -STEP
, 0, 0, 0);
1298 GetCursorPos(&pt_old
);
1299 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
);
1300 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, 0, 0, 0);
1301 GetCursorPos(&pt_old
);
1302 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
);
1303 mouse_event(MOUSEEVENTF_MOVE
, 0, -STEP
, 0, 0);
1304 GetCursorPos(&pt_old
);
1305 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 mouse_event(MOUSEEVENTF_MOVE
, 0, +STEP
, 0, 0);
1307 GetCursorPos(&pt_old
);
1308 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
);
1310 SetRect(&rc
, 50, 50, 151, 151);
1314 SetCursorPos(40, 40);
1315 GetCursorPos(&pt_old
);
1316 ok(pt_old
.x
== 50 && pt_old
.y
== 50, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
1317 SetCursorPos(160, 160);
1318 GetCursorPos(&pt_old
);
1319 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
1320 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, +STEP
, 0, 0);
1321 GetCursorPos(&pt_old
);
1322 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
1325 pt_new
.x
= pt_new
.y
= 150;
1327 UnhookWindowsHookEx(hook1
);
1329 /* Now check that mouse buttons do not change mouse position
1330 if we don't have MOUSEEVENTF_MOVE flag specified. */
1332 /* We reusing the same hook callback, so make it happy */
1333 pt_old
.x
= pt_new
.x
- STEP
;
1334 pt_old
.y
= pt_new
.y
- STEP
;
1335 mouse_event(MOUSEEVENTF_LEFTUP
, 123, 456, 0, 0);
1337 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1338 mouse_event(MOUSEEVENTF_RIGHTUP
, 456, 123, 0, 0);
1340 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1342 mouse_event(MOUSEEVENTF_LEFTUP
| MOUSEEVENTF_ABSOLUTE
, 123, 456, 0, 0);
1344 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1345 mouse_event(MOUSEEVENTF_RIGHTUP
| MOUSEEVENTF_ABSOLUTE
, 456, 123, 0, 0);
1347 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
1349 UnhookWindowsHookEx(hook2
);
1351 DestroyWindow(hwnd
);
1352 SetCursorPos(pt_org
.x
, pt_org
.y
);
1355 static void test_GetMouseMovePointsEx(void)
1358 #define MYERROR 0xdeadbeef
1361 MOUSEMOVEPOINT out
[200];
1364 /* Get a valid content for the input struct */
1365 if(!GetCursorPos(&point
)) {
1366 win_skip("GetCursorPos() failed with error %u\n", GetLastError());
1369 memset(&in
, 0, sizeof(MOUSEMOVEPOINT
));
1373 /* test first parameter
1374 * everything different than sizeof(MOUSEMOVEPOINT)
1375 * is expected to fail with ERROR_INVALID_PARAMETER
1377 SetLastError(MYERROR
);
1378 retval
= pGetMouseMovePointsEx(0, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1379 if (retval
== ERROR_INVALID_PARAMETER
)
1381 win_skip( "GetMouseMovePointsEx broken on WinME\n" );
1384 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1385 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1386 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1388 SetLastError(MYERROR
);
1389 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1390 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1391 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1392 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1394 SetLastError(MYERROR
);
1395 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)+1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1396 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1397 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1398 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1400 /* test second and third parameter
1402 SetLastError(MYERROR
);
1403 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1404 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1405 ok(GetLastError() == ERROR_NOACCESS
|| GetLastError() == MYERROR
,
1406 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1408 SetLastError(MYERROR
);
1409 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1410 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1411 ok(ERROR_NOACCESS
== GetLastError(),
1412 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1414 SetLastError(MYERROR
);
1415 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1416 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1417 ok(ERROR_NOACCESS
== GetLastError(),
1418 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1420 SetLastError(MYERROR
);
1422 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, count
, GMMP_USE_DISPLAY_POINTS
);
1424 ok(GetLastError() == ERROR_POINT_NOT_FOUND
, "unexpected error %u\n", GetLastError());
1426 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1428 /* test fourth parameter
1429 * a value higher than 64 is expected to fail with ERROR_INVALID_PARAMETER
1431 SetLastError(MYERROR
);
1433 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1434 ok(retval
== count
, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1435 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1436 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1438 SetLastError(MYERROR
);
1440 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1442 ok(GetLastError() == ERROR_POINT_NOT_FOUND
, "unexpected error %u\n", GetLastError());
1444 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1446 SetLastError(MYERROR
);
1448 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1450 ok(GetLastError() == ERROR_POINT_NOT_FOUND
, "unexpected error %u\n", GetLastError());
1452 ok((0 <= retval
) && (retval
<= count
), "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1454 SetLastError(MYERROR
);
1455 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1456 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1457 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1458 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1460 /* it was not possible to force an error with the fifth parameter on win2k */
1462 /* test combinations of wrong parameters to see which error wins */
1463 SetLastError(MYERROR
);
1464 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1465 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1466 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1467 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1469 SetLastError(MYERROR
);
1470 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1471 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1472 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1473 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1475 SetLastError(MYERROR
);
1476 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1477 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1478 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1479 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1481 SetLastError(MYERROR
);
1482 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1483 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1484 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == MYERROR
,
1485 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1491 static void test_GetRawInputDeviceList(void)
1493 RAWINPUTDEVICELIST devices
[32];
1494 UINT ret
, oret
, devcount
, odevcount
;
1497 SetLastError(0xdeadbeef);
1498 ret
= pGetRawInputDeviceList(NULL
, NULL
, 0);
1499 err
= GetLastError();
1500 ok(ret
== -1, "expected -1, got %d\n", ret
);
1501 ok(err
== ERROR_INVALID_PARAMETER
, "expected 87, got %d\n", err
);
1503 SetLastError(0xdeadbeef);
1504 ret
= pGetRawInputDeviceList(NULL
, NULL
, sizeof(devices
[0]));
1505 err
= GetLastError();
1506 ok(ret
== -1, "expected -1, got %d\n", ret
);
1507 ok(err
== ERROR_NOACCESS
, "expected 998, got %d\n", err
);
1510 ret
= pGetRawInputDeviceList(NULL
, &devcount
, sizeof(devices
[0]));
1511 ok(ret
== 0, "expected 0, got %d\n", ret
);
1512 ok(devcount
> 0, "expected non-zero\n");
1514 SetLastError(0xdeadbeef);
1516 ret
= pGetRawInputDeviceList(devices
, &devcount
, sizeof(devices
[0]));
1517 err
= GetLastError();
1518 ok(ret
== -1, "expected -1, got %d\n", ret
);
1519 ok(err
== ERROR_INSUFFICIENT_BUFFER
, "expected 122, got %d\n", err
);
1520 ok(devcount
> 0, "expected non-zero\n");
1522 /* devcount contains now the correct number of devices */
1523 ret
= pGetRawInputDeviceList(devices
, &devcount
, sizeof(devices
[0]));
1524 ok(ret
> 0, "expected non-zero\n");
1526 /* check if variable changes from larger to smaller value */
1527 devcount
= odevcount
= sizeof(devices
) / sizeof(devices
[0]);
1528 oret
= ret
= pGetRawInputDeviceList(devices
, &odevcount
, sizeof(devices
[0]));
1529 ok(ret
> 0, "expected non-zero\n");
1530 ok(devcount
== odevcount
, "expected %d, got %d\n", devcount
, odevcount
);
1531 devcount
= odevcount
;
1532 odevcount
= sizeof(devices
) / sizeof(devices
[0]);
1533 ret
= pGetRawInputDeviceList(NULL
, &odevcount
, sizeof(devices
[0]));
1534 ok(ret
== 0, "expected 0, got %d\n", ret
);
1535 ok(odevcount
== oret
, "expected %d, got %d\n", oret
, odevcount
);
1538 static void test_key_map(void)
1540 HKL kl
= GetKeyboardLayout(0);
1543 static const UINT numpad_collisions
[][2] = {
1544 { VK_NUMPAD0
, VK_INSERT
},
1545 { VK_NUMPAD1
, VK_END
},
1546 { VK_NUMPAD2
, VK_DOWN
},
1547 { VK_NUMPAD3
, VK_NEXT
},
1548 { VK_NUMPAD4
, VK_LEFT
},
1549 { VK_NUMPAD6
, VK_RIGHT
},
1550 { VK_NUMPAD7
, VK_HOME
},
1551 { VK_NUMPAD8
, VK_UP
},
1552 { VK_NUMPAD9
, VK_PRIOR
},
1555 s
= MapVirtualKeyExA(VK_SHIFT
, MAPVK_VK_TO_VSC
, kl
);
1556 ok(s
!= 0, "MapVirtualKeyEx(VK_SHIFT) should return non-zero\n");
1557 sL
= MapVirtualKeyExA(VK_LSHIFT
, MAPVK_VK_TO_VSC
, kl
);
1558 ok(s
== sL
|| broken(sL
== 0), /* win9x */
1559 "%x != %x\n", s
, sL
);
1561 kL
= MapVirtualKeyExA(0x2a, MAPVK_VSC_TO_VK
, kl
);
1562 ok(kL
== VK_SHIFT
, "Scan code -> vKey = %x (not VK_SHIFT)\n", kL
);
1563 kR
= MapVirtualKeyExA(0x36, MAPVK_VSC_TO_VK
, kl
);
1564 ok(kR
== VK_SHIFT
, "Scan code -> vKey = %x (not VK_SHIFT)\n", kR
);
1566 kL
= MapVirtualKeyExA(0x2a, MAPVK_VSC_TO_VK_EX
, kl
);
1567 ok(kL
== VK_LSHIFT
|| broken(kL
== 0), /* win9x */
1568 "Scan code -> vKey = %x (not VK_LSHIFT)\n", kL
);
1569 kR
= MapVirtualKeyExA(0x36, MAPVK_VSC_TO_VK_EX
, kl
);
1570 ok(kR
== VK_RSHIFT
|| broken(kR
== 0), /* win9x */
1571 "Scan code -> vKey = %x (not VK_RSHIFT)\n", kR
);
1573 /* test that MAPVK_VSC_TO_VK prefers the non-numpad vkey if there's ambiguity */
1574 for (i
= 0; i
< sizeof(numpad_collisions
)/sizeof(numpad_collisions
[0]); i
++)
1576 UINT numpad_scan
= MapVirtualKeyExA(numpad_collisions
[i
][0], MAPVK_VK_TO_VSC
, kl
);
1577 UINT other_scan
= MapVirtualKeyExA(numpad_collisions
[i
][1], MAPVK_VK_TO_VSC
, kl
);
1579 /* do they really collide for this layout? */
1580 if (numpad_scan
&& other_scan
== numpad_scan
)
1582 UINT vkey
= MapVirtualKeyExA(numpad_scan
, MAPVK_VSC_TO_VK
, kl
);
1583 ok(vkey
!= numpad_collisions
[i
][0],
1584 "Got numpad vKey %x for scan code %x when there was another choice\n",
1593 static const struct tounicode_tests
1597 WCHAR chr
; /* if vk is 0, lookup vk using this char */
1599 WCHAR expect_buf
[4];
1602 { 'A', 0, 0, 1, {'a',0}},
1603 { 'A', ctrl
, 0, 1, {1, 0}},
1604 { 'A', shift
|ctrl
, 0, 1, {1, 0}},
1605 { VK_TAB
, ctrl
, 0, 0, {}},
1606 { VK_TAB
, shift
|ctrl
, 0, 0, {}},
1607 { VK_RETURN
, ctrl
, 0, 1, {'\n', 0}},
1608 { VK_RETURN
, shift
|ctrl
, 0, 0, {}},
1609 { '4', ctrl
, 0, 0, {}},
1610 { '4', shift
|ctrl
, 0, 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
, '<', 0, {}},
1628 { 0, ctrl
, '=', 0, {}},
1629 { 0, ctrl
, '>', 0, {}},
1630 { 0, ctrl
, '?', 0, {}},
1631 { 0, ctrl
, '@', 1, {0}},
1632 { 0, ctrl
, '[', 1, {0x1b}},
1633 { 0, ctrl
, '\\', 1, {0x1c}},
1634 { 0, ctrl
, ']', 1, {0x1d}},
1635 { 0, ctrl
, '^', 1, {0x1e}},
1636 { 0, ctrl
, '_', 1, {0x1f}},
1637 { 0, ctrl
, '`', 0, {}},
1640 static void test_ToUnicode(void)
1644 const BYTE SC_RETURN
= 0x1c, SC_TAB
= 0x0f, SC_A
= 0x1e;
1645 const BYTE HIGHEST_BIT
= 0x80;
1647 for(i
=0; i
<256; i
++)
1651 SetLastError(0xdeadbeef);
1652 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, state
, wStr
, 4, 0);
1653 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1655 win_skip("ToUnicode is not implemented\n");
1659 ok(ret
== 1, "ToUnicode for Return key didn't return 1 (was %i)\n", ret
);
1662 ok(wStr
[0]=='\r', "ToUnicode for CTRL + Return was %i (expected 13)\n", wStr
[0]);
1663 ok(wStr
[1]==0 || broken(wStr
[1]!=0) /* nt4 */,
1664 "ToUnicode didn't null-terminate the buffer when there was room.\n");
1667 for (i
= 0; i
< sizeof(utests
) / sizeof(utests
[0]); i
++)
1669 UINT vk
= utests
[i
].vk
, mod
= utests
[i
].modifiers
, scan
;
1673 short vk_ret
= VkKeyScanW(utests
[i
].chr
);
1674 if (vk_ret
== -1) continue;
1676 if (vk_ret
& 0x100) mod
|= shift
;
1677 if (vk_ret
& 0x200) mod
|= ctrl
;
1679 scan
= MapVirtualKeyW(vk
, MAPVK_VK_TO_VSC
);
1681 state
[VK_SHIFT
] = state
[VK_LSHIFT
] = (mod
& shift
) ? HIGHEST_BIT
: 0;
1682 state
[VK_CONTROL
] = state
[VK_LCONTROL
] = (mod
& ctrl
) ? HIGHEST_BIT
: 0;
1684 ret
= ToUnicode(vk
, scan
, state
, wStr
, 4, 0);
1685 ok(ret
== utests
[i
].expect_ret
, "%d: got %d expected %d\n", i
, ret
, utests
[i
].expect_ret
);
1687 ok(!lstrcmpW(wStr
, utests
[i
].expect_buf
), "%d: got %s expected %s\n", i
, wine_dbgstr_w(wStr
),
1688 wine_dbgstr_w(utests
[i
].expect_buf
));
1691 state
[VK_SHIFT
] = state
[VK_LSHIFT
] = 0;
1692 state
[VK_CONTROL
] = state
[VK_LCONTROL
] = 0;
1694 ret
= ToUnicode(VK_TAB
, SC_TAB
, NULL
, wStr
, 4, 0);
1695 ok(ret
== 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret
);
1696 ret
= ToUnicode(VK_RETURN
, SC_RETURN
, NULL
, wStr
, 4, 0);
1697 ok(ret
== 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret
);
1698 ret
= ToUnicode('A', SC_A
, NULL
, wStr
, 4, 0);
1699 ok(ret
== 0, "ToUnicode with NULL keystate didn't return 0 (was %i)\n", ret
);
1700 ret
= ToUnicodeEx(VK_TAB
, SC_TAB
, NULL
, wStr
, 4, 0, GetKeyboardLayout(0));
1701 ok(ret
== 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret
);
1702 ret
= ToUnicodeEx(VK_RETURN
, SC_RETURN
, NULL
, wStr
, 4, 0, GetKeyboardLayout(0));
1703 ok(ret
== 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret
);
1704 ret
= ToUnicodeEx('A', SC_A
, NULL
, wStr
, 4, 0, GetKeyboardLayout(0));
1705 ok(ret
== 0, "ToUnicodeEx with NULL keystate didn't return 0 (was %i)\n", ret
);
1708 static void test_ToAscii(void)
1712 const BYTE SC_RETURN
= 0x1c, SC_A
= 0x1e;
1713 const BYTE HIGHEST_BIT
= 0x80;
1716 memset(state
, 0, sizeof(state
));
1719 ret
= ToAscii(VK_RETURN
, SC_RETURN
, state
, &character
, 0);
1720 ok(ret
== 1, "ToAscii for Return key didn't return 1 (was %i)\n", ret
);
1721 ok(character
== '\r', "ToAscii for Return was %i (expected 13)\n", character
);
1724 ret
= ToAscii('A', SC_A
, state
, &character
, 0);
1725 ok(ret
== 1, "ToAscii for character 'A' didn't return 1 (was %i)\n", ret
);
1726 ok(character
== 'a', "ToAscii for character 'A' was %i (expected %i)\n", character
, 'a');
1728 state
[VK_CONTROL
] |= HIGHEST_BIT
;
1729 state
[VK_LCONTROL
] |= HIGHEST_BIT
;
1731 ret
= ToAscii(VK_RETURN
, SC_RETURN
, state
, &character
, 0);
1732 ok(ret
== 1, "ToAscii for CTRL + Return key didn't return 1 (was %i)\n", ret
);
1733 ok(character
== '\n', "ToAscii for CTRL + Return was %i (expected 10)\n", character
);
1736 ret
= ToAscii('A', SC_A
, state
, &character
, 0);
1737 ok(ret
== 1, "ToAscii for CTRL + character 'A' didn't return 1 (was %i)\n", ret
);
1738 ok(character
== 1, "ToAscii for CTRL + character 'A' was %i (expected 1)\n", character
);
1740 state
[VK_SHIFT
] |= HIGHEST_BIT
;
1741 state
[VK_LSHIFT
] |= HIGHEST_BIT
;
1742 ret
= ToAscii(VK_RETURN
, SC_RETURN
, state
, &character
, 0);
1743 ok(ret
== 0, "ToAscii for CTRL + Shift + Return key didn't return 0 (was %i)\n", ret
);
1745 ret
= ToAscii(VK_RETURN
, SC_RETURN
, NULL
, &character
, 0);
1746 ok(ret
== 0, "ToAscii for NULL keystate didn't return 0 (was %i)\n", ret
);
1747 ret
= ToAscii('A', SC_A
, NULL
, &character
, 0);
1748 ok(ret
== 0, "ToAscii for NULL keystate didn't return 0 (was %i)\n", ret
);
1749 ret
= ToAsciiEx(VK_RETURN
, SC_RETURN
, NULL
, &character
, 0, GetKeyboardLayout(0));
1750 ok(ret
== 0, "ToAsciiEx for NULL keystate didn't return 0 (was %i)\n", ret
);
1751 ret
= ToAsciiEx('A', SC_A
, NULL
, &character
, 0, GetKeyboardLayout(0));
1752 ok(ret
== 0, "ToAsciiEx for NULL keystate didn't return 0 (was %i)\n", ret
);
1755 static void test_get_async_key_state(void)
1757 /* input value sanity checks */
1758 ok(0 == GetAsyncKeyState(1000000), "GetAsyncKeyState did not return 0\n");
1759 ok(0 == GetAsyncKeyState(-1000000), "GetAsyncKeyState did not return 0\n");
1762 static void test_keyboard_layout_name(void)
1765 char klid
[KL_NAMELENGTH
];
1767 if (0) /* crashes on native system */
1768 ret
= GetKeyboardLayoutNameA(NULL
);
1770 SetLastError(0xdeadbeef);
1771 ret
= GetKeyboardLayoutNameW(NULL
);
1772 ok(!ret
, "got %d\n", ret
);
1773 ok(GetLastError() == ERROR_NOACCESS
, "got %d\n", GetLastError());
1775 if (GetKeyboardLayout(0) != (HKL
)(ULONG_PTR
)0x04090409) return;
1778 ret
= GetKeyboardLayoutNameA(klid
);
1779 ok(ret
, "GetKeyboardLayoutNameA failed %u\n", GetLastError());
1780 ok(!strcmp(klid
, "00000409"), "expected 00000409, got %s\n", klid
);
1783 static void test_key_names(void)
1788 LONG lparam
= 0x1d << 16;
1790 memset( buffer
, 0xcc, sizeof(buffer
) );
1791 ret
= GetKeyNameTextA( lparam
, buffer
, sizeof(buffer
) );
1792 ok( ret
> 0, "wrong len %u for '%s'\n", ret
, buffer
);
1793 ok( ret
== strlen(buffer
), "wrong len %u for '%s'\n", ret
, buffer
);
1795 memset( buffer
, 0xcc, sizeof(buffer
) );
1797 ret
= GetKeyNameTextA( lparam
, buffer
, prev
);
1798 ok( ret
== prev
- 1, "wrong len %u for '%s'\n", ret
, buffer
);
1799 ok( ret
== strlen(buffer
), "wrong len %u for '%s'\n", ret
, buffer
);
1801 memset( buffer
, 0xcc, sizeof(buffer
) );
1802 ret
= GetKeyNameTextA( lparam
, buffer
, 0 );
1803 ok( ret
== 0, "wrong len %u for '%s'\n", ret
, buffer
);
1804 ok( buffer
[0] == 0, "wrong string '%s'\n", buffer
);
1806 memset( bufferW
, 0xcc, sizeof(bufferW
) );
1807 ret
= GetKeyNameTextW( lparam
, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
1808 ok( ret
> 0, "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1809 ok( ret
== lstrlenW(bufferW
), "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1811 memset( bufferW
, 0xcc, sizeof(bufferW
) );
1813 ret
= GetKeyNameTextW( lparam
, bufferW
, prev
);
1814 ok( ret
== prev
- 1, "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1815 ok( ret
== lstrlenW(bufferW
), "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1817 memset( bufferW
, 0xcc, sizeof(bufferW
) );
1818 ret
= GetKeyNameTextW( lparam
, bufferW
, 0 );
1819 ok( ret
== 0, "wrong len %u for %s\n", ret
, wine_dbgstr_w(bufferW
) );
1820 ok( bufferW
[0] == 0xcccc, "wrong string %s\n", wine_dbgstr_w(bufferW
) );
1823 static void simulate_click(BOOL left
, int x
, int y
)
1829 memset(input
, 0, sizeof(input
));
1830 input
[0].type
= INPUT_MOUSE
;
1831 U(input
[0]).mi
.dx
= x
;
1832 U(input
[0]).mi
.dy
= y
;
1833 U(input
[0]).mi
.dwFlags
= left
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_RIGHTDOWN
;
1834 input
[1].type
= INPUT_MOUSE
;
1835 U(input
[1]).mi
.dx
= x
;
1836 U(input
[1]).mi
.dy
= y
;
1837 U(input
[1]).mi
.dwFlags
= left
? MOUSEEVENTF_LEFTUP
: MOUSEEVENTF_RIGHTUP
;
1838 events_no
= SendInput(2, input
, sizeof(input
[0]));
1839 ok(events_no
== 2, "SendInput returned %d\n", events_no
);
1842 static BOOL
wait_for_message( MSG
*msg
)
1848 ret
= PeekMessageA(msg
, 0, 0, 0, PM_REMOVE
);
1851 if (msg
->message
== WM_PAINT
) DispatchMessageA(msg
);
1854 else if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, 100, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
1856 if (!ret
) msg
->message
= 0;
1860 static BOOL
wait_for_event(HANDLE event
, int timeout
)
1862 DWORD end_time
= GetTickCount() + timeout
;
1866 if(MsgWaitForMultipleObjects(1, &event
, FALSE
, timeout
, QS_ALLINPUT
) == WAIT_OBJECT_0
)
1868 while(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
1869 DispatchMessageA(&msg
);
1870 timeout
= end_time
- GetTickCount();
1871 }while(timeout
> 0);
1876 static WNDPROC def_static_proc
;
1877 static DWORD hittest_no
;
1878 static LRESULT WINAPI
static_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1880 if (msg
== WM_NCHITTEST
)
1882 /* break infinite hittest loop */
1883 if(hittest_no
> 50) return HTCLIENT
;
1887 return def_static_proc(hwnd
, msg
, wp
, lp
);
1897 static DWORD WINAPI
create_static_win(void *arg
)
1899 struct thread_data
*thread_data
= arg
;
1902 win
= CreateWindowA("static", "static", WS_VISIBLE
| WS_POPUP
,
1903 100, 100, 100, 100, 0, NULL
, NULL
, NULL
);
1904 ok(win
!= 0, "CreateWindow failed\n");
1905 def_static_proc
= (void*)SetWindowLongPtrA(win
,
1906 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
1907 thread_data
->win
= win
;
1909 SetEvent(thread_data
->start_event
);
1910 wait_for_event(thread_data
->end_event
, 5000);
1914 static void test_Input_mouse(void)
1916 BOOL got_button_down
, got_button_up
;
1917 HWND hwnd
, button_win
, static_win
;
1918 struct thread_data thread_data
;
1924 button_win
= CreateWindowA("button", "button", WS_VISIBLE
| WS_POPUP
,
1925 100, 100, 100, 100, 0, NULL
, NULL
, NULL
);
1926 ok(button_win
!= 0, "CreateWindow failed\n");
1929 hwnd
= WindowFromPoint(pt
);
1930 if (hwnd
!= button_win
)
1932 skip("there's another window covering test window\n");
1933 DestroyWindow(button_win
);
1937 /* simple button click test */
1938 simulate_click(TRUE
, 150, 150);
1939 got_button_down
= got_button_up
= FALSE
;
1940 while (wait_for_message(&msg
))
1942 DispatchMessageA(&msg
);
1944 if (msg
.message
== WM_LBUTTONDOWN
)
1946 got_button_down
= TRUE
;
1948 else if (msg
.message
== WM_LBUTTONUP
)
1950 got_button_up
= TRUE
;
1954 ok(got_button_down
, "expected WM_LBUTTONDOWN message\n");
1955 ok(got_button_up
, "expected WM_LBUTTONUP message\n");
1957 /* click through HTTRANSPARENT child window */
1958 static_win
= CreateWindowA("static", "static", WS_VISIBLE
| WS_CHILD
,
1959 0, 0, 100, 100, button_win
, NULL
, NULL
, NULL
);
1960 ok(static_win
!= 0, "CreateWindow failed\n");
1961 def_static_proc
= (void*)SetWindowLongPtrA(static_win
,
1962 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
1963 simulate_click(FALSE
, 150, 150);
1965 got_button_down
= got_button_up
= FALSE
;
1966 while (wait_for_message(&msg
))
1968 DispatchMessageA(&msg
);
1970 if (msg
.message
== WM_RBUTTONDOWN
)
1972 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
1973 got_button_down
= TRUE
;
1975 else if (msg
.message
== WM_RBUTTONUP
)
1977 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
1978 got_button_up
= TRUE
;
1982 ok(hittest_no
&& hittest_no
<50, "expected WM_NCHITTEST message\n");
1983 ok(got_button_down
, "expected WM_RBUTTONDOWN message\n");
1984 ok(got_button_up
, "expected WM_RBUTTONUP message\n");
1985 DestroyWindow(static_win
);
1987 /* click through HTTRANSPARENT top-level window */
1988 static_win
= CreateWindowA("static", "static", WS_VISIBLE
| WS_POPUP
,
1989 100, 100, 100, 100, 0, NULL
, NULL
, NULL
);
1990 ok(static_win
!= 0, "CreateWindow failed\n");
1991 def_static_proc
= (void*)SetWindowLongPtrA(static_win
,
1992 GWLP_WNDPROC
, (LONG_PTR
)static_hook_proc
);
1993 simulate_click(TRUE
, 150, 150);
1995 got_button_down
= got_button_up
= FALSE
;
1996 while (wait_for_message(&msg
))
1998 DispatchMessageA(&msg
);
2000 if (msg
.message
== WM_LBUTTONDOWN
)
2002 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2003 got_button_down
= TRUE
;
2005 else if (msg
.message
== WM_LBUTTONUP
)
2007 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2008 got_button_up
= TRUE
;
2012 ok(hittest_no
&& hittest_no
<50, "expected WM_NCHITTEST message\n");
2013 todo_wine
ok(got_button_down
, "expected WM_LBUTTONDOWN message\n");
2014 todo_wine
ok(got_button_up
, "expected WM_LBUTTONUP message\n");
2015 DestroyWindow(static_win
);
2017 /* click on HTTRANSPARENT top-level window that belongs to other thread */
2018 thread_data
.start_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2019 ok(thread_data
.start_event
!= NULL
, "CreateEvent failed\n");
2020 thread_data
.end_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2021 ok(thread_data
.end_event
!= NULL
, "CreateEvent failed\n");
2022 thread
= CreateThread(NULL
, 0, create_static_win
, &thread_data
, 0, NULL
);
2023 ok(thread
!= NULL
, "CreateThread failed\n");
2025 got_button_down
= got_button_up
= FALSE
;
2026 WaitForSingleObject(thread_data
.start_event
, INFINITE
);
2027 simulate_click(FALSE
, 150, 150);
2028 while (wait_for_message(&msg
))
2030 DispatchMessageA(&msg
);
2032 if (msg
.message
== WM_RBUTTONDOWN
)
2033 got_button_down
= TRUE
;
2034 else if (msg
.message
== WM_RBUTTONUP
)
2035 got_button_up
= TRUE
;
2037 SetEvent(thread_data
.end_event
);
2038 WaitForSingleObject(thread
, INFINITE
);
2039 ok(hittest_no
&& hittest_no
<50, "expected WM_NCHITTEST message\n");
2040 ok(!got_button_down
, "unexpected WM_RBUTTONDOWN message\n");
2041 ok(!got_button_up
, "unexpected WM_RBUTTONUP message\n");
2043 /* click on HTTRANSPARENT top-level window that belongs to other thread,
2044 * thread input queues are attached */
2045 thread
= CreateThread(NULL
, 0, create_static_win
, &thread_data
, 0, &thread_id
);
2046 ok(thread
!= NULL
, "CreateThread failed\n");
2048 got_button_down
= got_button_up
= FALSE
;
2049 WaitForSingleObject(thread_data
.start_event
, INFINITE
);
2050 ok(AttachThreadInput(thread_id
, GetCurrentThreadId(), TRUE
),
2051 "AttachThreadInput failed\n");
2052 while (wait_for_message(&msg
)) DispatchMessageA(&msg
);
2053 SetWindowPos(thread_data
.win
, button_win
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
2054 simulate_click(TRUE
, 150, 150);
2055 while (wait_for_message(&msg
))
2057 DispatchMessageA(&msg
);
2059 if (msg
.message
== WM_LBUTTONDOWN
)
2060 got_button_down
= TRUE
;
2061 else if (msg
.message
== WM_LBUTTONUP
)
2062 got_button_up
= TRUE
;
2064 SetEvent(thread_data
.end_event
);
2065 WaitForSingleObject(thread
, INFINITE
);
2066 todo_wine
ok(hittest_no
> 50, "expected loop with WM_NCHITTEST messages\n");
2067 ok(!got_button_down
, "unexpected WM_LBUTTONDOWN message\n");
2068 ok(!got_button_up
, "unexpected WM_LBUTTONUP message\n");
2070 /* click after SetCapture call */
2071 hwnd
= CreateWindowA("button", "button", WS_VISIBLE
| WS_POPUP
,
2072 0, 0, 100, 100, 0, NULL
, NULL
, NULL
);
2073 ok(hwnd
!= 0, "CreateWindow failed\n");
2074 SetCapture(button_win
);
2075 got_button_down
= got_button_up
= FALSE
;
2076 simulate_click(FALSE
, 50, 50);
2077 while (wait_for_message(&msg
))
2079 DispatchMessageA(&msg
);
2081 if (msg
.message
== WM_RBUTTONDOWN
)
2083 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2084 got_button_down
= TRUE
;
2086 else if (msg
.message
== WM_RBUTTONUP
)
2088 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2089 got_button_up
= TRUE
;
2093 ok(got_button_down
, "expected WM_RBUTTONDOWN message\n");
2094 ok(got_button_up
, "expected WM_RBUTTONUP message\n");
2095 DestroyWindow(hwnd
);
2097 /* click on child window after SetCapture call */
2098 hwnd
= CreateWindowA("button", "button2", WS_VISIBLE
| WS_CHILD
,
2099 0, 0, 100, 100, button_win
, NULL
, NULL
, NULL
);
2100 ok(hwnd
!= 0, "CreateWindow failed\n");
2101 got_button_down
= got_button_up
= FALSE
;
2102 simulate_click(TRUE
, 150, 150);
2103 while (wait_for_message(&msg
))
2105 DispatchMessageA(&msg
);
2107 if (msg
.message
== WM_LBUTTONDOWN
)
2109 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2110 got_button_down
= TRUE
;
2112 else if (msg
.message
== WM_LBUTTONUP
)
2114 ok(msg
.hwnd
== button_win
, "msg.hwnd = %p\n", msg
.hwnd
);
2115 got_button_up
= TRUE
;
2119 ok(got_button_down
, "expected WM_LBUTTONDOWN message\n");
2120 ok(got_button_up
, "expected WM_LBUTTONUP message\n");
2121 DestroyWindow(hwnd
);
2122 ok(ReleaseCapture(), "ReleaseCapture failed\n");
2124 CloseHandle(thread_data
.start_event
);
2125 CloseHandle(thread_data
.end_event
);
2126 DestroyWindow(button_win
);
2130 static LRESULT WINAPI
MsgCheckProcA(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2132 if (message
== WM_USER
+1)
2134 HWND hwnd
= (HWND
)lParam
;
2135 ok(GetFocus() == hwnd
, "thread expected focus %p, got %p\n", hwnd
, GetFocus());
2136 ok(GetActiveWindow() == hwnd
, "thread expected active %p, got %p\n", hwnd
, GetActiveWindow());
2138 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2151 static DWORD WINAPI
thread_proc(void *param
)
2154 struct wnd_event
*wnd_event
= param
;
2157 if (wnd_event
->wait_event
)
2159 ok(WaitForSingleObject(wnd_event
->wait_event
, INFINITE
) == WAIT_OBJECT_0
,
2160 "WaitForSingleObject failed\n");
2161 CloseHandle(wnd_event
->wait_event
);
2164 if (wnd_event
->attach_from
)
2166 ret
= AttachThreadInput(wnd_event
->attach_from
, GetCurrentThreadId(), TRUE
);
2167 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2170 if (wnd_event
->attach_to
)
2172 ret
= AttachThreadInput(GetCurrentThreadId(), wnd_event
->attach_to
, TRUE
);
2173 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2176 wnd_event
->hwnd
= CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW
,
2177 100, 100, 200, 200, 0, 0, 0, NULL
);
2178 ok(wnd_event
->hwnd
!= 0, "Failed to create overlapped window\n");
2180 if (wnd_event
->setWindows
)
2182 SetFocus(wnd_event
->hwnd
);
2183 SetActiveWindow(wnd_event
->hwnd
);
2186 SetEvent(wnd_event
->start_event
);
2188 while (GetMessageA(&msg
, 0, 0, 0))
2190 TranslateMessage(&msg
);
2191 DispatchMessageA(&msg
);
2197 static void test_attach_input(void)
2202 struct wnd_event wnd_event
;
2206 cls
.lpfnWndProc
= MsgCheckProcA
;
2209 cls
.hInstance
= GetModuleHandleA(0);
2211 cls
.hCursor
= LoadCursorW( NULL
, (LPCWSTR
)IDC_ARROW
);
2212 cls
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2213 cls
.lpszMenuName
= NULL
;
2214 cls
.lpszClassName
= "TestWindowClass";
2215 if(!RegisterClassA(&cls
)) return;
2217 wnd_event
.wait_event
= NULL
;
2218 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2219 wnd_event
.attach_from
= 0;
2220 wnd_event
.attach_to
= 0;
2221 wnd_event
.setWindows
= FALSE
;
2222 if (!wnd_event
.start_event
)
2224 win_skip("skipping interthread message test under win9x\n");
2228 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2229 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2231 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2232 CloseHandle(wnd_event
.start_event
);
2234 ourWnd
= CreateWindowExA(0, "TestWindowClass", NULL
, WS_OVERLAPPEDWINDOW
,
2235 0, 0, 0, 0, 0, 0, 0, NULL
);
2236 ok(ourWnd
!= 0, "failed to create ourWnd window\n");
2238 Wnd2
= CreateWindowExA(0, "TestWindowClass", NULL
, WS_OVERLAPPEDWINDOW
,
2239 0, 0, 0, 0, 0, 0, 0, NULL
);
2240 ok(Wnd2
!= 0, "failed to create Wnd2 window\n");
2243 SetActiveWindow(ourWnd
);
2245 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2246 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2248 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2249 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2251 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)ourWnd
);
2253 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2254 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2255 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2256 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2258 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, 0);
2260 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2261 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2263 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2264 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2265 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)ourWnd
);
2267 SetActiveWindow(Wnd2
);
2269 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2270 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2272 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)Wnd2
);
2274 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2275 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2276 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2277 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2279 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, 0);
2281 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2282 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2284 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2285 CloseHandle(hThread
);
2287 wnd_event
.wait_event
= NULL
;
2288 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2289 wnd_event
.attach_from
= 0;
2290 wnd_event
.attach_to
= 0;
2291 wnd_event
.setWindows
= TRUE
;
2293 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2294 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2296 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2297 CloseHandle(wnd_event
.start_event
);
2300 SetActiveWindow(ourWnd
);
2302 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2303 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2305 ok(GetActiveWindow() == wnd_event
.hwnd
, "expected active %p, got %p\n", wnd_event
.hwnd
, GetActiveWindow());
2306 ok(GetFocus() == wnd_event
.hwnd
, "expected focus %p, got %p\n", wnd_event
.hwnd
, GetFocus());
2308 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)wnd_event
.hwnd
);
2310 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2311 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2313 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
2314 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
2316 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)wnd_event
.hwnd
);
2318 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2319 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2321 ok(GetActiveWindow() == wnd_event
.hwnd
, "expected active %p, got %p\n", wnd_event
.hwnd
, GetActiveWindow());
2322 ok(GetFocus() == wnd_event
.hwnd
, "expected focus %p, got %p\n", wnd_event
.hwnd
, GetFocus());
2324 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)wnd_event
.hwnd
);
2327 SetActiveWindow(Wnd2
);
2328 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2329 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2331 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, (LPARAM
)Wnd2
);
2333 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, FALSE
);
2334 ok(ret
, "AttachThreadInput error %d\n", GetLastError());
2336 ok(GetActiveWindow() == Wnd2
, "expected active %p, got %p\n", Wnd2
, GetActiveWindow());
2337 ok(GetFocus() == Wnd2
, "expected focus %p, got %p\n", Wnd2
, GetFocus());
2339 SendMessageA(wnd_event
.hwnd
, WM_USER
+1, 0, 0);
2341 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2342 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2344 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2345 CloseHandle(hThread
);
2347 wnd_event
.wait_event
= CreateEventW(NULL
, 0, 0, NULL
);
2348 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2349 wnd_event
.attach_from
= 0;
2350 wnd_event
.attach_to
= 0;
2351 wnd_event
.setWindows
= TRUE
;
2353 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2354 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2356 SetLastError(0xdeadbeef);
2357 ret
= AttachThreadInput(GetCurrentThreadId(), tid
, TRUE
);
2358 ok(!ret
, "AttachThreadInput succeeded\n");
2359 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| broken(GetLastError() == 0xdeadbeef) /* <= Win XP */,
2360 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2362 SetLastError(0xdeadbeef);
2363 ret
= AttachThreadInput(tid
, GetCurrentThreadId(), TRUE
);
2364 ok(!ret
, "AttachThreadInput succeeded\n");
2365 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| broken(GetLastError() == 0xdeadbeef) /* <= Win XP */,
2366 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2368 SetEvent(wnd_event
.wait_event
);
2370 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2371 CloseHandle(wnd_event
.start_event
);
2373 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2374 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2376 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2377 CloseHandle(hThread
);
2379 wnd_event
.wait_event
= NULL
;
2380 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2381 wnd_event
.attach_from
= GetCurrentThreadId();
2382 wnd_event
.attach_to
= 0;
2383 wnd_event
.setWindows
= FALSE
;
2386 SetActiveWindow(ourWnd
);
2388 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2389 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2391 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2392 CloseHandle(wnd_event
.start_event
);
2394 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2395 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2397 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2398 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2400 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2401 CloseHandle(hThread
);
2403 wnd_event
.wait_event
= NULL
;
2404 wnd_event
.start_event
= CreateEventW(NULL
, 0, 0, NULL
);
2405 wnd_event
.attach_from
= 0;
2406 wnd_event
.attach_to
= GetCurrentThreadId();
2407 wnd_event
.setWindows
= FALSE
;
2410 SetActiveWindow(ourWnd
);
2412 hThread
= CreateThread(NULL
, 0, thread_proc
, &wnd_event
, 0, &tid
);
2413 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
2415 ok(WaitForSingleObject(wnd_event
.start_event
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2416 CloseHandle(wnd_event
.start_event
);
2418 ok(GetActiveWindow() == ourWnd
, "expected active %p, got %p\n", ourWnd
, GetActiveWindow());
2419 ok(GetFocus() == ourWnd
, "expected focus %p, got %p\n", ourWnd
, GetFocus());
2421 ret
= PostMessageA(wnd_event
.hwnd
, WM_QUIT
, 0, 0);
2422 ok(ret
, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
2424 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2425 CloseHandle(hThread
);
2426 DestroyWindow(ourWnd
);
2427 DestroyWindow(Wnd2
);
2430 static DWORD WINAPI
get_key_state_thread(void *arg
)
2432 HANDLE
*semaphores
= arg
;
2435 ReleaseSemaphore(semaphores
[0], 1, NULL
);
2436 result
= WaitForSingleObject(semaphores
[1], 1000);
2437 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2439 result
= GetKeyState('X');
2440 ok((result
& 0x8000) || broken(!(result
& 0x8000)), /* > Win 2003 */
2441 "expected that highest bit is set, got %x\n", result
);
2443 ReleaseSemaphore(semaphores
[0], 1, NULL
);
2444 result
= WaitForSingleObject(semaphores
[1], 1000);
2445 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2447 result
= GetKeyState('X');
2448 ok(!(result
& 0x8000), "expected that highest bit is unset, got %x\n", result
);
2453 static void test_GetKeyState(void)
2455 HANDLE semaphores
[2];
2460 semaphores
[0] = CreateSemaphoreA(NULL
, 0, 1, NULL
);
2461 ok(semaphores
[0] != NULL
, "CreateSemaphoreA failed %u\n", GetLastError());
2462 semaphores
[1] = CreateSemaphoreA(NULL
, 0, 1, NULL
);
2463 ok(semaphores
[1] != NULL
, "CreateSemaphoreA failed %u\n", GetLastError());
2465 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
2466 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
2467 ok(hwnd
!= NULL
, "CreateWindowA failed %u\n", GetLastError());
2469 thread
= CreateThread(NULL
, 0, get_key_state_thread
, semaphores
, 0, NULL
);
2470 ok(thread
!= NULL
, "CreateThread failed %u\n", GetLastError());
2471 result
= WaitForSingleObject(semaphores
[0], 1000);
2472 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2475 keybd_event('X', 0, 0, 0);
2477 ReleaseSemaphore(semaphores
[1], 1, NULL
);
2478 result
= WaitForSingleObject(semaphores
[0], 1000);
2479 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2481 keybd_event('X', 0, KEYEVENTF_KEYUP
, 0);
2483 ReleaseSemaphore(semaphores
[1], 1, NULL
);
2484 result
= WaitForSingleObject(thread
, 1000);
2485 ok(result
== WAIT_OBJECT_0
, "WaitForSingleObject returned %u\n", result
);
2486 CloseHandle(thread
);
2488 DestroyWindow(hwnd
);
2489 CloseHandle(semaphores
[0]);
2490 CloseHandle(semaphores
[1]);
2495 init_function_pointers();
2499 test_Input_blackbox();
2500 test_Input_whitebox();
2501 test_Input_unicode();
2504 else win_skip("SendInput is not available\n");
2507 test_mouse_ll_hook();
2511 test_get_async_key_state();
2512 test_keyboard_layout_name();
2514 test_attach_input();
2517 if(pGetMouseMovePointsEx
)
2518 test_GetMouseMovePointsEx();
2520 win_skip("GetMouseMovePointsEx is not available\n");
2522 if(pGetRawInputDeviceList
)
2523 test_GetRawInputDeviceList();
2525 win_skip("GetRawInputDeviceList is not available\n");