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 accompished 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
56 #include "wine/test.h"
60 static long timetag
= 0x10000000;
62 static UINT (WINAPI
*pSendInput
) (UINT
, INPUT
*, size_t);
63 static int (WINAPI
*pGetMouseMovePointsEx
) (UINT
, LPMOUSEMOVEPOINT
, LPMOUSEMOVEPOINT
, int, DWORD
);
65 #define MAXKEYEVENTS 6
66 #define MAXKEYMESSAGES MAXKEYEVENTS /* assuming a key event generates one
67 and only one message */
69 /* keyboard message names, sorted as their value */
70 static const char *MSGNAME
[]={"WM_KEYDOWN", "WM_KEYUP", "WM_CHAR","WM_DEADCHAR",
71 "WM_SYSKEYDOWN", "WM_SYSKEYUP", "WM_SYSCHAR", "WM_SYSDEADCHAR" ,"WM_KEYLAST"};
73 /* keyevents, add more as needed */
75 { ALTDOWN
= 1, ALTUP
, XDOWN
, XUP
, SHIFTDOWN
, SHIFTUP
, CTRLDOWN
, CTRLUP
} KEV
;
77 static const int GETVKEY
[]={0, VK_MENU
, VK_MENU
, 'X', 'X', VK_SHIFT
, VK_SHIFT
, VK_CONTROL
, VK_CONTROL
};
78 /* matching scan codes */
79 static const int GETSCAN
[]={0, 0x38, 0x38, 0x2D, 0x2D, 0x2A, 0x2A, 0x1D, 0x1D };
80 /* matching updown events */
81 static const int GETUPDOWN
[]={0, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
, 0, KEYEVENTF_KEYUP
};
82 /* matching descripts */
83 static const char *getdesc
[]={"", "+alt","-alt","+X","-X","+shift","-shift","+ctrl","-ctrl"};
85 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define our own type */
97 #define ADDTOINPUTS(kev) \
98 inputs[evtctr].type = INPUT_KEYBOARD; \
99 ((TEST_INPUT*)inputs)[evtctr].u.ki.wVk = GETVKEY[ kev]; \
100 ((TEST_INPUT*)inputs)[evtctr].u.ki.wScan = GETSCAN[ kev]; \
101 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwFlags = GETUPDOWN[ kev]; \
102 ((TEST_INPUT*)inputs)[evtctr].u.ki.dwExtraInfo = 0; \
103 ((TEST_INPUT*)inputs)[evtctr].u.ki.time = ++timetag; \
112 /*******************************************
113 * add new test sets here
114 * the software will make all combinations of the
115 * keyevent defined here
117 static const struct {
119 KEV keydwn
[MAXKEYEVENTS
];
120 KEV keyup
[MAXKEYEVENTS
];
122 { 2, { ALTDOWN
, XDOWN
}, { ALTUP
, XUP
}},
123 { 3, { ALTDOWN
, XDOWN
, SHIFTDOWN
}, { ALTUP
, XUP
, SHIFTUP
}},
124 { 3, { ALTDOWN
, XDOWN
, CTRLDOWN
}, { ALTUP
, XUP
, CTRLUP
}},
125 { 3, { SHIFTDOWN
, XDOWN
, CTRLDOWN
}, { SHIFTUP
, XUP
, CTRLUP
}},
126 { 0 } /* mark the end */
129 /**********************adapted from input.c **********************************/
131 static BYTE InputKeyStateTable
[256];
132 static BYTE AsyncKeyStateTable
[256];
133 static BYTE TrackSysKey
= 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
134 or a WM_KEYUP message */
139 unsigned long count
: 16;
140 unsigned long code
: 8;
141 unsigned long extended
: 1;
142 unsigned long unused
: 2;
143 unsigned long win_internal
: 2;
144 unsigned long context
: 1;
145 unsigned long previous
: 1;
146 unsigned long transition
: 1;
151 static void init_function_pointers(void)
153 HMODULE hdll
= GetModuleHandleA("user32");
155 #define GET_PROC(func) \
156 p ## func = (void*)GetProcAddress(hdll, #func); \
158 trace("GetProcAddress(%s) failed\n", #func);
161 GET_PROC(GetMouseMovePointsEx
)
166 static int KbdMessage( KEV kev
, WPARAM
*pwParam
, LPARAM
*plParam
)
169 int VKey
= GETVKEY
[kev
];
175 keylp
.lp1
.code
= GETSCAN
[kev
];
176 keylp
.lp1
.extended
= 0 ;/* FIXME (ki->dwFlags & KEYEVENTF_EXTENDEDKEY) != 0; */
177 keylp
.lp1
.win_internal
= 0;
179 if (GETUPDOWN
[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 keylp
.lp1
.previous
= 1;
192 keylp
.lp1
.transition
= 1;
196 keylp
.lp1
.previous
= (InputKeyStateTable
[VKey
] & 0x80) != 0;
197 keylp
.lp1
.transition
= 0;
198 if (!(InputKeyStateTable
[VKey
] & 0x80)) InputKeyStateTable
[VKey
] ^= 0x01;
199 InputKeyStateTable
[VKey
] |= 0x80;
200 AsyncKeyStateTable
[VKey
] |= 0x80;
202 message
= WM_KEYDOWN
;
203 if( (InputKeyStateTable
[VK_MENU
] & 0x80) &&
204 !(InputKeyStateTable
[VK_CONTROL
] & 0x80)) {
205 message
= WM_SYSKEYDOWN
;
210 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
212 if( plParam
) *plParam
= keylp
.lp2
;
213 if( pwParam
) *pwParam
= VKey
;
217 /****************************** end copy input.c ****************************/
220 * . prepare the keyevents for SendInputs
221 * . calculate the "expected" messages
222 * . Send the events to our window
223 * . retrieve the messages from the input queue
226 static void do_test( HWND hwnd
, int seqnr
, const KEV td
[] )
228 INPUT inputs
[MAXKEYEVENTS
];
229 KMSG expmsg
[MAXKEYEVENTS
];
236 TrackSysKey
=0; /* see input.c */
237 for( i
= 0; i
< MAXKEYEVENTS
; i
++) {
239 strcat(buf
, getdesc
[td
[i
]]);
241 expmsg
[i
].message
= KbdMessage(td
[i
], &(expmsg
[i
].wParam
), &(expmsg
[i
].lParam
)); /* see queue_kbd_event() */
243 expmsg
[i
].message
= 0;
245 for( kmctr
= 0; kmctr
< MAXKEYEVENTS
&& expmsg
[kmctr
].message
; kmctr
++)
247 assert( evtctr
<= MAXKEYEVENTS
);
248 assert( evtctr
== pSendInput(evtctr
, &inputs
[0], sizeof(INPUT
)));
250 if (winetest_debug
> 1)
251 trace("======== key stroke sequence #%d: %s =============\n",
253 while( PeekMessage(&msg
,hwnd
,WM_KEYFIRST
,WM_KEYLAST
,PM_REMOVE
) ) {
254 if (winetest_debug
> 1)
255 trace("message[%d] %-15s wParam %04lx lParam %08lx time %x\n", i
,
256 MSGNAME
[msg
.message
- WM_KEYFIRST
], msg
.wParam
, msg
.lParam
, msg
.time
);
258 ok( msg
.message
== expmsg
[i
].message
&&
259 msg
.wParam
== expmsg
[i
].wParam
&&
260 msg
.lParam
== expmsg
[i
].lParam
,
261 "wrong message! expected:\n"
262 "message[%d] %-15s wParam %04lx lParam %08lx\n",i
,
263 MSGNAME
[(expmsg
[i
]).message
- WM_KEYFIRST
],
264 expmsg
[i
].wParam
, expmsg
[i
].lParam
);
268 if (winetest_debug
> 1)
269 trace("%d messages retrieved\n", i
);
270 ok( i
== kmctr
, "message count is wrong: got %d expected: %d\n", i
, kmctr
);
273 /* test all combinations of the specified key events */
274 static void TestASet( HWND hWnd
, int nrkev
, const KEV kevdwn
[], const KEV kevup
[] )
278 KEV kbuf
[MAXKEYEVENTS
];
279 assert( nrkev
==2 || nrkev
==3);
280 for(i
=0;i
<MAXKEYEVENTS
;i
++) kbuf
[i
]=0;
281 /* two keys involved gives 4 test cases */
283 for(i
=0;i
<nrkev
;i
++) {
284 for(j
=0;j
<nrkev
;j
++) {
286 kbuf
[1] = kevdwn
[1-i
];
288 kbuf
[3] = kevup
[1-j
];
289 do_test( hWnd
, count
++, kbuf
);
293 /* three keys involved gives 36 test cases */
295 for(i
=0;i
<nrkev
;i
++){
296 for(j
=0;j
<nrkev
;j
++){
298 for(k
=0;k
<nrkev
;k
++){
299 if(k
==i
|| k
==j
) continue;
300 for(l
=0;l
<nrkev
;l
++){
301 for(m
=0;m
<nrkev
;m
++){
303 for(n
=0;n
<nrkev
;n
++){
304 if(n
==l
||n
==m
) continue;
311 do_test( hWnd
, count
++, kbuf
);
321 /* test each set specified in the global testkeyset array */
322 static void TestSysKeys( HWND hWnd
)
325 for(i
=0; testkeyset
[i
].nrkev
;i
++)
326 TestASet( hWnd
, testkeyset
[i
].nrkev
, testkeyset
[i
].keydwn
,
327 testkeyset
[i
].keyup
);
330 static LRESULT CALLBACK
WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
336 /* window has focus, now do the test */
337 if( hWnd
== hWndTest
) TestSysKeys( hWnd
);
342 PostQuitMessage( 0 );
346 return( DefWindowProcA( hWnd
, msg
, wParam
, lParam
) );
352 static void test_Input_whitebox(void)
356 HANDLE hInstance
= GetModuleHandleA( NULL
);
358 wclass
.lpszClassName
= "InputSysKeyTestClass";
359 wclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
360 wclass
.lpfnWndProc
= WndProc
;
361 wclass
.hInstance
= hInstance
;
362 wclass
.hIcon
= LoadIconA( 0, (LPSTR
)IDI_APPLICATION
);
363 wclass
.hCursor
= LoadCursorA( NULL
, IDC_ARROW
);
364 wclass
.hbrBackground
= (HBRUSH
)( COLOR_WINDOW
+ 1);
365 wclass
.lpszMenuName
= 0;
366 wclass
.cbClsExtra
= 0;
367 wclass
.cbWndExtra
= 0;
368 assert (RegisterClassA( &wclass
));
369 /* create the test window that will receive the keystrokes */
370 assert ( hWndTest
= CreateWindowA( wclass
.lpszClassName
, "InputSysKeyTest",
371 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, 100, 100,
372 NULL
, NULL
, hInstance
, NULL
) );
373 ShowWindow( hWndTest
, SW_SHOW
);
374 UpdateWindow( hWndTest
);
376 /* flush pending messages */
377 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
379 SendMessageA(hWndTest
, WM_USER
, 0, 0);
380 DestroyWindow(hWndTest
);
383 static void empty_message_queue(void) {
385 while(PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
386 TranslateMessage(&msg
);
387 DispatchMessage(&msg
);
391 struct transition_s
{
410 UINT message
; /* the WM_* code */
411 msg_flags_t flags
; /* message props */
412 WPARAM wParam
; /* expected value of wParam */
413 LPARAM lParam
; /* expected value of lParam */
416 struct sendinput_test_s
{
420 struct transition_s expected_transitions
[MAXKEYEVENTS
+1];
421 struct message expected_messages
[MAXKEYMESSAGES
+1];
422 } sendinput_test
[] = {
424 {VK_LMENU
, 0, 0, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
425 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_LMENU
}, {WM_SYSKEYDOWN
}, {0}}},
426 {'F', 0, 0, {{'F', 0x00}, {0}},
427 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
},
429 {WM_SYSCOMMAND
}, {0}}},
430 {'F', KEYEVENTF_KEYUP
, 0, {{'F', 0x80}, {0}},
431 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
432 {VK_LMENU
, KEYEVENTF_KEYUP
, 0, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
433 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
436 {VK_LCONTROL
, 0, 0, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
437 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
438 {'O', 0, 0, {{'O', 0x00}, {0}},
439 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
440 {'O', KEYEVENTF_KEYUP
, 0, {{'O', 0x80}, {0}},
441 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
442 {VK_LCONTROL
, KEYEVENTF_KEYUP
, 0, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
443 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
445 /* test ALT+CTRL+X */
446 {VK_LMENU
, 0, 0, {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
447 {{WM_SYSKEYDOWN
, hook
}, {WM_SYSKEYDOWN
}, {0}}},
448 {VK_LCONTROL
, 0, 0, {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
449 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
450 {'X', 0, 0, {{'X', 0x00}, {0}},
451 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
452 {'X', KEYEVENTF_KEYUP
, 0, {{'X', 0x80}, {0}},
453 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
454 {VK_LCONTROL
, KEYEVENTF_KEYUP
, 0, {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
455 {{WM_SYSKEYUP
, hook
}, {WM_SYSKEYUP
}, {0}}},
456 {VK_LMENU
, KEYEVENTF_KEYUP
, 0, {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
457 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
460 {VK_LSHIFT
, 0, 0, {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
461 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {0}}},
462 {'A', 0, 0, {{'A', 0x00}, {0}},
463 {{WM_KEYDOWN
, hook
}, {WM_KEYDOWN
}, {WM_CHAR
}, {0}}},
464 {'A', KEYEVENTF_KEYUP
, 0, {{'A', 0x80}, {0}},
465 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
466 {VK_LSHIFT
, KEYEVENTF_KEYUP
, 0, {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
467 {{WM_KEYUP
, hook
}, {WM_KEYUP
}, {0}}},
468 /* test L-SHIFT & R-SHIFT: */
469 /* RSHIFT == LSHIFT */
471 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
472 {{WM_KEYDOWN
, hook
|wparam
, VK_RSHIFT
},
474 {VK_RSHIFT
, KEYEVENTF_KEYUP
, 0,
475 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
476 {{WM_KEYUP
, hook
, hook
|wparam
, VK_RSHIFT
},
479 /* LSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
480 {VK_LSHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
481 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
482 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_EXTENDED
},
483 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
484 {VK_LSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
485 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
486 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
487 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
488 /* RSHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
489 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
490 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
491 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
492 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
493 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
494 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
495 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
496 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
497 /* SHIFT == LSHIFT */
499 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
500 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_SHIFT
, 0},
501 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
502 {VK_SHIFT
, KEYEVENTF_KEYUP
, 0,
503 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
504 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_SHIFT
, LLKHF_UP
},
505 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
506 /* SHIFT | KEYEVENTF_EXTENDEDKEY == RSHIFT */
507 {VK_SHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
508 {{VK_SHIFT
, 0x00}, {VK_RSHIFT
, 0x00}, {0}},
509 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_SHIFT
, LLKHF_EXTENDED
},
510 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
511 {VK_SHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
512 {{VK_SHIFT
, 0x80}, {VK_RSHIFT
, 0x80}, {0}},
513 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_SHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
514 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
516 /* test L-CONTROL & R-CONTROL: */
517 /* RCONTROL == LCONTROL */
519 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
520 {{WM_KEYDOWN
, hook
|wparam
, VK_RCONTROL
},
521 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
522 {VK_RCONTROL
, KEYEVENTF_KEYUP
, 0,
523 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
524 {{WM_KEYUP
, hook
|wparam
, VK_RCONTROL
},
525 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
526 /* LCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
527 {VK_LCONTROL
, KEYEVENTF_EXTENDEDKEY
, 0,
528 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
529 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_EXTENDED
},
530 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
531 {VK_LCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
532 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
533 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
534 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
535 /* RCONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
536 {VK_RCONTROL
, KEYEVENTF_EXTENDEDKEY
, 0,
537 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
538 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_EXTENDED
},
539 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
540 {VK_RCONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
541 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
542 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RCONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
543 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
544 /* CONTROL == LCONTROL */
546 {{VK_CONTROL
, 0x00}, {VK_LCONTROL
, 0x00}, {0}},
547 {{WM_KEYDOWN
, hook
|wparam
, VK_CONTROL
},
548 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, 0}, {0}}},
549 {VK_CONTROL
, KEYEVENTF_KEYUP
, 0,
550 {{VK_CONTROL
, 0x80}, {VK_LCONTROL
, 0x80}, {0}},
551 {{WM_KEYUP
, hook
|wparam
, VK_CONTROL
},
552 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
}, {0}}},
553 /* CONTROL | KEYEVENTF_EXTENDEDKEY == RCONTROL */
554 {VK_CONTROL
, KEYEVENTF_EXTENDEDKEY
, 0,
555 {{VK_CONTROL
, 0x00}, {VK_RCONTROL
, 0x00}, {0}},
556 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_CONTROL
, LLKHF_EXTENDED
},
557 {WM_KEYDOWN
, wparam
|lparam
, VK_CONTROL
, KF_EXTENDED
}, {0}}},
558 {VK_CONTROL
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
559 {{VK_CONTROL
, 0x80}, {VK_RCONTROL
, 0x80}, {0}},
560 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_CONTROL
, LLKHF_UP
|LLKHF_EXTENDED
},
561 {WM_KEYUP
, wparam
|lparam
, VK_CONTROL
, KF_UP
|KF_EXTENDED
}, {0}}},
563 /* test L-MENU & R-MENU: */
566 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
567 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_RMENU
},
568 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
569 {VK_RMENU
, KEYEVENTF_KEYUP
, 1,
570 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
571 {{WM_KEYUP
, hook
|wparam
, VK_RMENU
},
572 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
573 {WM_SYSCOMMAND
}, {0}}},
574 /* LMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
575 {VK_LMENU
, KEYEVENTF_EXTENDEDKEY
, 0,
576 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
577 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_EXTENDED
},
578 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
579 {VK_LMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 1,
580 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
581 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_LMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
582 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
583 {WM_SYSCOMMAND
}, {0}}},
584 /* RMENU | KEYEVENTF_EXTENDEDKEY == RMENU */
585 {VK_RMENU
, KEYEVENTF_EXTENDEDKEY
, 0,
586 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
587 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_EXTENDED
},
588 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
589 {VK_RMENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 1,
590 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
591 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RMENU
, LLKHF_UP
|LLKHF_EXTENDED
},
592 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
593 {WM_SYSCOMMAND
}, {0}}},
596 {{VK_MENU
, 0x00}, {VK_LMENU
, 0x00}, {0}},
597 {{WM_SYSKEYDOWN
, hook
|wparam
, VK_MENU
},
598 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, 0}, {0}}},
599 {VK_MENU
, KEYEVENTF_KEYUP
, 1,
600 {{VK_MENU
, 0x80}, {VK_LMENU
, 0x80}, {0}},
601 {{WM_KEYUP
, hook
|wparam
, VK_MENU
},
602 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
},
603 {WM_SYSCOMMAND
}, {0}}},
604 /* MENU | KEYEVENTF_EXTENDEDKEY == RMENU */
605 {VK_MENU
, KEYEVENTF_EXTENDEDKEY
, 0,
606 {{VK_MENU
, 0x00}, {VK_RMENU
, 0x00}, {0}},
607 {{WM_SYSKEYDOWN
, hook
|wparam
|lparam
, VK_MENU
, LLKHF_EXTENDED
},
608 {WM_SYSKEYDOWN
, wparam
|lparam
, VK_MENU
, KF_EXTENDED
}, {0}}},
609 {VK_MENU
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 1,
610 {{VK_MENU
, 0x80}, {VK_RMENU
, 0x80}, {0}},
611 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_MENU
, LLKHF_UP
|LLKHF_EXTENDED
},
612 {WM_SYSKEYUP
, wparam
|lparam
, VK_MENU
, KF_UP
|KF_EXTENDED
},
613 {WM_SYSCOMMAND
}, {0}}},
615 /* test LSHIFT & RSHIFT */
617 {{VK_SHIFT
, 0x00}, {VK_LSHIFT
, 0x00}, {0}},
618 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_LSHIFT
, 0},
619 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
620 {VK_RSHIFT
, KEYEVENTF_EXTENDEDKEY
, 0,
621 {{VK_RSHIFT
, 0x00}, {0}},
622 {{WM_KEYDOWN
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_EXTENDED
},
623 {WM_KEYDOWN
, wparam
|lparam
, VK_SHIFT
, 0}, {0}}},
624 {VK_RSHIFT
, KEYEVENTF_KEYUP
| KEYEVENTF_EXTENDEDKEY
, 0,
625 {{VK_RSHIFT
, 0x80}, {0}},
626 {{WM_KEYUP
, hook
|wparam
|lparam
, VK_RSHIFT
, LLKHF_UP
|LLKHF_EXTENDED
},
627 {WM_KEYUP
, optional
}, {0}}},
628 {VK_LSHIFT
, KEYEVENTF_KEYUP
, 0,
629 {{VK_SHIFT
, 0x80}, {VK_LSHIFT
, 0x80}, {0}},
630 {{WM_KEYUP
, hook
|wparam
, VK_LSHIFT
},
631 {WM_KEYUP
, wparam
|lparam
, VK_SHIFT
, KF_UP
}, {0}}},
633 {0, 0, 0, {{0}}, {{0}}} /* end */
636 static struct message sent_messages
[MAXKEYMESSAGES
];
637 static UINT sent_messages_cnt
;
639 /* Verify that only specified key state transitions occur */
640 static void compare_and_check(int id
, BYTE
*ks1
, BYTE
*ks2
, struct sendinput_test_s
*test
)
642 int i
, failcount
= 0;
643 struct transition_s
*t
= test
->expected_transitions
;
645 const struct message
*expected
= test
->expected_messages
;
648 int matched
= ((ks1
[t
->wVk
]&0x80) == (t
->before_state
&0x80)
649 && (ks2
[t
->wVk
]&0x80) == (~t
->before_state
&0x80));
651 if (!matched
&& test
->_todo_wine
)
655 ok(matched
, "%02d: %02x from %02x -> %02x "
656 "instead of %02x -> %02x\n", id
, t
->wVk
,
657 ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
658 ~t
->before_state
&0x80);
661 ok(matched
, "%02d: %02x from %02x -> %02x "
662 "instead of %02x -> %02x\n", id
, t
->wVk
,
663 ks1
[t
->wVk
]&0x80, ks2
[t
->wVk
]&0x80, t
->before_state
,
664 ~t
->before_state
&0x80);
666 ks2
[t
->wVk
] = ks1
[t
->wVk
]; /* clear the match */
669 for (i
= 0; i
< 256; i
++)
670 if (ks2
[i
] != ks1
[i
] && test
->_todo_wine
)
674 ok(FALSE
, "%02d: %02x from %02x -> %02x unexpected\n", id
, i
, ks1
[i
], ks2
[i
]);
677 ok(ks2
[i
] == ks1
[i
], "%02d: %02x from %02x -> %02x unexpected\n",
678 id
, i
, ks1
[i
], ks2
[i
]);
680 while (expected
->message
&& actual_cnt
< sent_messages_cnt
)
682 const struct message
*actual
= &sent_messages
[actual_cnt
];
684 if (expected
->message
== actual
->message
)
686 ok((expected
->flags
& hook
) == (actual
->flags
& hook
),
687 "%x/%x: the msg 0x%04x should have been sent by a hook\n",
688 test
->wVk
, test
->dwFlags
, expected
->message
);
690 if (expected
->flags
& wparam
)
692 if (expected
->wParam
!= actual
->wParam
&& test
->_todo_wine
)
696 ok(FALSE
, "%x/%x: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
697 test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
700 ok(expected
->wParam
== actual
->wParam
,
701 "%x/%x: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
702 test
->wVk
, test
->dwFlags
, expected
->message
, expected
->wParam
, actual
->wParam
);
704 if (expected
->flags
& lparam
)
706 if (expected
->lParam
!= actual
->lParam
&& test
->_todo_wine
)
710 ok(FALSE
, "%x/%x: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
711 test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
714 ok(expected
->lParam
== actual
->lParam
,
715 "%x/%x: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
716 test
->wVk
, test
->dwFlags
, expected
->message
, expected
->lParam
, actual
->lParam
);
719 else if (expected
->flags
& optional
)
724 else if (test
->_todo_wine
)
729 "%x/%x: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
730 test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
734 "%x/%x: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
735 test
->wVk
, test
->dwFlags
, expected
->message
, actual
->message
);
740 /* skip all optional trailing messages */
741 while (expected
->message
&& (expected
->flags
& optional
))
745 if (expected
->message
|| actual_cnt
< sent_messages_cnt
)
747 if (test
->_todo_wine
)
751 ok(FALSE
, "%x/%x: the msg sequence is not complete: expected %04x - actual %04x\n",
752 test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
755 ok(FALSE
, "%x/%x: the msg sequence is not complete: expected %04x - actual %04x\n",
756 test
->wVk
, test
->dwFlags
, expected
->message
, sent_messages
[actual_cnt
].message
);
759 if( test
->_todo_wine
&& !failcount
) /* succeeded yet marked todo */
761 ok(TRUE
, "%x/%x: marked \"todo_wine\" but succeeds\n", test
->wVk
, test
->dwFlags
);
763 sent_messages_cnt
= 0;
766 /* WndProc2 checks that we get at least the messages specified */
767 static LRESULT CALLBACK
WndProc2(HWND hWnd
, UINT Msg
, WPARAM wParam
,
770 if (winetest_debug
> 1) trace("MSG: %8x W:%8lx L:%8lx\n", Msg
, wParam
, lParam
);
772 if (Msg
!= WM_PAINT
&&
774 Msg
!= WM_SYNCPAINT
&&
775 Msg
!= WM_ERASEBKGND
&&
776 Msg
!= WM_NCHITTEST
&&
779 Msg
!= WM_DEVICECHANGE
)
781 sent_messages
[sent_messages_cnt
].message
= Msg
;
782 sent_messages
[sent_messages_cnt
].flags
= 0;
783 sent_messages
[sent_messages_cnt
].wParam
= wParam
;
784 sent_messages
[sent_messages_cnt
++].lParam
= HIWORD(lParam
) & (KF_UP
|KF_EXTENDED
);
786 return DefWindowProc(hWnd
, Msg
, wParam
, lParam
);
789 static LRESULT CALLBACK
hook_proc(int code
, WPARAM wparam
, LPARAM lparam
)
791 KBDLLHOOKSTRUCT
*hook_info
= (KBDLLHOOKSTRUCT
*)lparam
;
793 if (code
== HC_ACTION
)
795 sent_messages
[sent_messages_cnt
].message
= wparam
;
796 sent_messages
[sent_messages_cnt
].flags
= hook
;
797 sent_messages
[sent_messages_cnt
].wParam
= hook_info
->vkCode
;
798 sent_messages
[sent_messages_cnt
++].lParam
= hook_info
->flags
& (LLKHF_UP
|LLKHF_EXTENDED
);
800 if(0) /* For some reason not stable on Wine */
802 if (wparam
== WM_KEYDOWN
|| wparam
== WM_SYSKEYDOWN
)
803 ok(!(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000), "key %x should be up\n", hook_info
->vkCode
);
804 else if (wparam
== WM_KEYUP
|| wparam
== WM_SYSKEYUP
)
805 ok(GetAsyncKeyState(hook_info
->vkCode
) & 0x8000, "key %x should be down\n", hook_info
->vkCode
);
808 if (winetest_debug
> 1)
809 trace("Hook: w=%lx vk:%8x sc:%8x fl:%8x %lx\n", wparam
,
810 hook_info
->vkCode
, hook_info
->scanCode
, hook_info
->flags
, hook_info
->dwExtraInfo
);
812 return CallNextHookEx( 0, code
, wparam
, lparam
);
814 static void test_Input_blackbox(void)
818 BYTE ks1
[256], ks2
[256];
819 LONG_PTR prevWndProc
;
825 skip("SendInput is not available\n");
829 window
= CreateWindow("Static", NULL
, WS_POPUP
|WS_HSCROLL
|WS_VSCROLL
830 |WS_VISIBLE
, 0, 0, 200, 60, NULL
, NULL
,
832 ok(window
!= NULL
, "error: %d\n", (int) GetLastError());
834 hook
= SetWindowsHookExA(WH_KEYBOARD_LL
, hook_proc
, GetModuleHandleA( NULL
), 0);
836 /* must process all initial messages, otherwise X11DRV_KeymapNotify unsets
837 * key state set by SendInput(). */
838 empty_message_queue();
840 prevWndProc
= SetWindowLongPtr(window
, GWLP_WNDPROC
, (LONG_PTR
) WndProc2
);
841 ok(prevWndProc
!= 0 || (prevWndProc
== 0 && GetLastError() == 0),
842 "error: %d\n", (int) GetLastError());
844 i
.type
= INPUT_KEYBOARD
;
846 i
.u
.ki
.dwExtraInfo
= 0;
848 for (ii
= 0; ii
< sizeof(sendinput_test
)/sizeof(struct sendinput_test_s
)-1;
850 GetKeyboardState(ks1
);
851 i
.u
.ki
.wScan
= ii
+1 /* useful for debugging */;
852 i
.u
.ki
.dwFlags
= sendinput_test
[ii
].dwFlags
;
853 i
.u
.ki
.wVk
= sendinput_test
[ii
].wVk
;
854 pSendInput(1, (INPUT
*)&i
, sizeof(TEST_INPUT
));
855 empty_message_queue();
856 GetKeyboardState(ks2
);
857 compare_and_check(ii
, ks1
, ks2
, &sendinput_test
[ii
]);
860 empty_message_queue();
861 DestroyWindow(window
);
862 UnhookWindowsHookEx(hook
);
865 static void test_keynames(void)
870 for (i
= 0; i
< 512; i
++)
872 strcpy(buff
, "----");
873 len
= GetKeyNameTextA(i
<< 16, buff
, sizeof(buff
));
874 ok(len
|| !buff
[0], "%d: Buffer is not zeroed\n", i
);
878 static POINT pt_old
, pt_new
;
882 static LRESULT CALLBACK
hook_proc1( int code
, WPARAM wparam
, LPARAM lparam
)
884 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
887 if (code
== HC_ACTION
)
889 /* This is our new cursor position */
891 /* Should return previous position */
893 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
895 /* Should set new position until hook chain is finished. */
896 pt
.x
= pt_old
.x
+ STEP
;
897 pt
.y
= pt_old
.y
+ STEP
;
898 SetCursorPos(pt
.x
, pt
.y
);
901 ok(pt1
.x
== pt_old
.x
&& pt1
.y
== pt_old
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
903 ok(pt1
.x
== pt
.x
&& pt1
.y
== pt
.y
, "Wrong set pos: (%d,%d)\n", pt1
.x
, pt1
.y
);
905 return CallNextHookEx( 0, code
, wparam
, lparam
);
908 static LRESULT CALLBACK
hook_proc2( int code
, WPARAM wparam
, LPARAM lparam
)
910 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
913 if (code
== HC_ACTION
)
915 ok(hook
->pt
.x
== pt_new
.x
&& hook
->pt
.y
== pt_new
.y
,
916 "Wrong hook coords: (%d %d) != (%d,%d)\n", hook
->pt
.x
, hook
->pt
.y
, pt_new
.x
, pt_new
.y
);
918 /* Should match position set above */
921 ok(pt
.x
== pt_old
.x
&& pt
.y
== pt_old
.y
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
923 ok(pt
.x
== pt_old
.x
+STEP
&& pt
.y
== pt_old
.y
+STEP
, "GetCursorPos: (%d,%d)\n", pt
.x
, pt
.y
);
925 return CallNextHookEx( 0, code
, wparam
, lparam
);
928 static void test_mouse_ll_hook(void)
935 GetCursorPos(&pt_org
);
936 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
937 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
938 SetCursorPos(100, 100);
940 hook2
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc2
, GetModuleHandleA(0), 0);
941 hook1
= SetWindowsHookExA(WH_MOUSE_LL
, hook_proc1
, GetModuleHandleA(0), 0);
943 GetCursorPos(&pt_old
);
944 mouse_event(MOUSEEVENTF_MOVE
, -STEP
, 0, 0, 0);
945 GetCursorPos(&pt_old
);
946 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
);
947 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, 0, 0, 0);
948 GetCursorPos(&pt_old
);
949 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
);
950 mouse_event(MOUSEEVENTF_MOVE
, 0, -STEP
, 0, 0);
951 GetCursorPos(&pt_old
);
952 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
);
953 mouse_event(MOUSEEVENTF_MOVE
, 0, +STEP
, 0, 0);
954 GetCursorPos(&pt_old
);
955 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
);
957 SetRect(&rc
, 50, 50, 151, 151);
961 SetCursorPos(40, 40);
962 GetCursorPos(&pt_old
);
963 ok(pt_old
.x
== 50 && pt_old
.y
== 50, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
964 SetCursorPos(160, 160);
965 GetCursorPos(&pt_old
);
966 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
967 mouse_event(MOUSEEVENTF_MOVE
, +STEP
, +STEP
, 0, 0);
968 GetCursorPos(&pt_old
);
969 ok(pt_old
.x
== 150 && pt_old
.y
== 150, "Wrong new pos: (%d,%d)\n", pt_new
.x
, pt_new
.y
);
972 pt_new
.x
= pt_new
.y
= 150;
974 UnhookWindowsHookEx(hook1
);
976 /* Now check that mouse buttons do not change mouse position
977 if we don't have MOUSEEVENTF_MOVE flag specified. */
979 /* We reusing the same hook callback, so make it happy */
980 pt_old
.x
= pt_new
.x
- STEP
;
981 pt_old
.y
= pt_new
.y
- STEP
;
982 mouse_event(MOUSEEVENTF_LEFTUP
, 123, 456, 0, 0);
984 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
985 mouse_event(MOUSEEVENTF_RIGHTUP
, 456, 123, 0, 0);
987 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
989 mouse_event(MOUSEEVENTF_LEFTUP
| MOUSEEVENTF_ABSOLUTE
, 123, 456, 0, 0);
991 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
992 mouse_event(MOUSEEVENTF_RIGHTUP
| MOUSEEVENTF_ABSOLUTE
, 456, 123, 0, 0);
994 ok(pt
.x
== pt_new
.x
&& pt
.y
== pt_new
.y
, "Position changed: (%d,%d)\n", pt
.x
, pt
.y
);
996 UnhookWindowsHookEx(hook2
);
998 SetCursorPos(pt_org
.x
, pt_org
.y
);
1001 static void test_GetMouseMovePointsEx(void)
1004 #define MYERROR 0xdeadbeef
1007 MOUSEMOVEPOINT out
[200];
1010 /* Get a valid content for the input struct */
1011 if(!GetCursorPos(&point
)) {
1012 skip("GetCursorPos() failed with error %u\n", GetLastError());
1015 memset(&in
, 0, sizeof(MOUSEMOVEPOINT
));
1019 /* test first parameter
1020 * everything different than sizeof(MOUSEMOVEPOINT)
1021 * is expected to fail with ERROR_INVALID_PARAMETER
1023 SetLastError(MYERROR
);
1024 retval
= pGetMouseMovePointsEx(0, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1025 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1026 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1027 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1029 SetLastError(MYERROR
);
1030 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1031 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1032 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1033 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1035 SetLastError(MYERROR
);
1036 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)+1, &in
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1037 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1038 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1039 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1041 /* test second and third parameter
1043 SetLastError(MYERROR
);
1044 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1045 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1046 ok(ERROR_NOACCESS
== GetLastError(),
1047 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1049 SetLastError(MYERROR
);
1050 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1051 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1052 ok(ERROR_NOACCESS
== GetLastError(),
1053 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1055 SetLastError(MYERROR
);
1056 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1057 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1058 ok(ERROR_NOACCESS
== GetLastError(),
1059 "expected error ERROR_NOACCESS, got %u\n", GetLastError());
1061 SetLastError(MYERROR
);
1063 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, count
, GMMP_USE_DISPLAY_POINTS
);
1065 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1066 ok(MYERROR
== GetLastError(),
1067 "expected error %d, got %u\n", MYERROR
, GetLastError());
1070 /* test fourth parameter
1071 * a value higher than 64 is expected to fail with ERROR_INVALID_PARAMETER
1073 SetLastError(MYERROR
);
1075 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1076 ok(retval
== count
, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1077 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1078 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1080 SetLastError(MYERROR
);
1082 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1084 ok(retval
== count
, "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1085 ok(MYERROR
== GetLastError(),
1086 "expected error %d, got %u\n", MYERROR
, GetLastError());
1089 SetLastError(MYERROR
);
1091 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, count
, GMMP_USE_DISPLAY_POINTS
);
1093 ok((0 <= retval
) && (retval
<= count
), "expected GetMouseMovePointsEx to succeed, got %d\n", retval
);
1094 ok(MYERROR
== GetLastError(),
1095 "expected error %d, got %u\n", MYERROR
, GetLastError());
1098 SetLastError(MYERROR
);
1099 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1100 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1101 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1102 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1104 /* it was not possible to force an error with the fifth parameter on win2k */
1106 /* test combinations of wrong parameters to see which error wins */
1107 SetLastError(MYERROR
);
1108 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, NULL
, out
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1109 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1110 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1111 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1113 SetLastError(MYERROR
);
1114 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
)-1, &in
, NULL
, BUFLIM
, GMMP_USE_DISPLAY_POINTS
);
1115 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1116 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1117 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1119 SetLastError(MYERROR
);
1120 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), NULL
, out
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1121 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1122 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1123 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1125 SetLastError(MYERROR
);
1126 retval
= pGetMouseMovePointsEx(sizeof(MOUSEMOVEPOINT
), &in
, NULL
, BUFLIM
+1, GMMP_USE_DISPLAY_POINTS
);
1127 ok(retval
== -1, "expected GetMouseMovePointsEx to fail, got %d\n", retval
);
1128 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1129 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1137 init_function_pointers();
1140 skip("SendInput is not available\n");
1142 test_Input_whitebox();
1144 test_Input_blackbox();
1146 test_mouse_ll_hook();
1148 if(pGetMouseMovePointsEx
)
1149 test_GetMouseMovePointsEx();
1151 skip("GetMouseMovePointsEx is not available\n");